projects
/
apps
/
pfixtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
We don't need a separate module here.
[apps/pfixtools.git]
/
main-srsd.c
diff --git
a/main-srsd.c
b/main-srsd.c
index
891f7ee
..
79f9e19
100644
(file)
--- a/
main-srsd.c
+++ b/
main-srsd.c
@@
-33,14
+33,11
@@
* Copyright © 2005-2007 Pierre Habouzit
*/
* Copyright © 2005-2007 Pierre Habouzit
*/
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <sys/epoll.h>
-#include <sys/stat.h>
+#include "common.h"
#include <srs2.h>
#include <srs2.h>
-#include "
common
.h"
+#include "
epoll
.h"
#include "mem.h"
#include "buffer.h"
#include "mem.h"
#include "buffer.h"
@@
-163,7
+160,7
@@
int process_srs(srs_t *srs, const char *domain, srsd_t *srsd)
return 0;
}
return 0;
}
-int start_listener(int
epollfd, int
port, bool decoder)
+int start_listener(int port, bool decoder)
{
struct sockaddr_in addr = {
.sin_family = AF_INET,
{
struct sockaddr_in addr = {
.sin_family = AF_INET,
@@
-231,18
+228,9
@@
void usage(void)
int main_loop(srs_t *srs, const char *domain, int port_enc, int port_dec)
{
int main_loop(srs_t *srs, const char *domain, int port_enc, int port_dec)
{
- int exitcode = EXIT_SUCCESS;
- int epollfd = epoll_create(128);
-
- if (epollfd < 0) {
- UNIXERR("epoll_create");
- exitcode = EXIT_FAILURE;
- goto error;
- }
-
- if (start_listener(epollfd, port_enc, false) < 0)
+ if (start_listener(port_enc, false) < 0)
return EXIT_FAILURE;
return EXIT_FAILURE;
- if (start_listener(
epollfd,
port_dec, true) < 0)
+ if (start_listener(port_dec, true) < 0)
return EXIT_FAILURE;
while (!sigint) {
return EXIT_FAILURE;
while (!sigint) {
@@
-253,8
+241,7
@@
int main_loop(srs_t *srs, const char *domain, int port_enc, int port_dec)
if (n < 0) {
if (errno != EAGAIN && errno != EINTR) {
UNIXERR("epoll_wait");
if (n < 0) {
if (errno != EAGAIN && errno != EINTR) {
UNIXERR("epoll_wait");
- exitcode = EXIT_FAILURE;
- break;
+ return EXIT_FAILURE;
}
continue;
}
}
continue;
}
@@
-328,10
+315,7
@@
int main_loop(srs_t *srs, const char *domain, int port_enc, int port_dec)
}
}
}
}
- close(epollfd);
-
- error:
- return exitcode;
+ return EXIT_SUCCESS;
}
static srs_t *srs_read_secrets(const char *sfile)
}
static srs_t *srs_read_secrets(const char *sfile)
@@
-382,17
+366,10
@@
int main(int argc, char *argv[])
int port_dec = DEFAULT_DECODER_PORT;
const char *pidfile = NULL;
int port_dec = DEFAULT_DECODER_PORT;
const char *pidfile = NULL;
- FILE *f = NULL;
int res;
srs_t *srs;
int res;
srs_t *srs;
- if (atexit(common_shutdown)) {
- fputs("Cannot hook my atexit function, quitting !\n", stderr);
- return EXIT_FAILURE;
- }
- common_initialize();
-
- for (int c = 0; (c = getopt(argc, argv, "he:d:p:u")) >= 0; ) {
+ for (int c = 0; (c = getopt(argc, argv, "hu" "e:d:p:")) >= 0; ) {
switch (c) {
case 'e':
port_enc = atoi(optarg);
switch (c) {
case 'e':
port_enc = atoi(optarg);
@@
-422,13
+399,9
@@
int main(int argc, char *argv[])
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}
- if (pidfile) {
- f = fopen(pidfile, "w");
- if (!f) {
- syslog(LOG_CRIT, "unable to write pidfile %s", pidfile);
- }
- fprintf(f, "%d\n", getpid());
- fflush(f);
+ if (pidfile_open(pidfile) < 0) {
+ syslog(LOG_CRIT, "unable to write pidfile %s", pidfile);
+ return EXIT_FAILURE;
}
if (!unsafe && drop_privileges(RUNAS_USER, RUNAS_GROUP) < 0) {
}
if (!unsafe && drop_privileges(RUNAS_USER, RUNAS_GROUP) < 0) {
@@
-441,19
+414,8
@@
int main(int argc, char *argv[])
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}
- if (f) {
- rewind(f);
- ftruncate(fileno(f), 0);
- fprintf(f, "%d\n", getpid());
- fflush(f);
- }
+ pidfile_refresh();
res = main_loop(srs, argv[optind], port_enc, port_dec);
res = main_loop(srs, argv[optind], port_enc, port_dec);
- if (f) {
- rewind(f);
- ftruncate(fileno(f), 0);
- fclose(f);
- f = NULL;
- }
syslog(LOG_INFO, "Stopping...");
return res;
}
syslog(LOG_INFO, "Stopping...");
return res;
}