diff options
author | Yang Tse <yangsita@gmail.com> | 2008-02-26 15:06:44 +0000 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2008-02-26 15:06:44 +0000 |
commit | 0d09f342c48b0d447fd506869959986da1746838 (patch) | |
tree | de9eead14a1ce4be7ecfd1039a30f6ad41f1014c /tests/server/sockfilt.c | |
parent | 9682c2037e964cd64ba581ceff61a04bb6395a6b (diff) |
refactor some code out to write_pidfile() in util.c
Diffstat (limited to 'tests/server/sockfilt.c')
-rw-r--r-- | tests/server/sockfilt.c | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index aeefb23bd..abe1b10fe 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -98,6 +98,17 @@ static volatile int sigpipe; /* Why? It's not used */ const char *serverlogfile = (char *)DEFAULT_LOGFILE; +bool use_ipv6 = FALSE; +unsigned short port = DEFAULT_PORT; +unsigned short connectport = 0; /* if non-zero, we activate this mode */ + +enum sockmode { + PASSIVE_LISTEN, /* as a server waiting for connections */ + PASSIVE_CONNECT, /* as a server, connected to a client */ + ACTIVE, /* as a client, connected to a server */ + ACTIVE_DISCONNECT /* as a client, disconnected from server */ +}; + static void lograw(unsigned char *buffer, ssize_t len) { char data[120]; @@ -143,17 +154,6 @@ static void sigpipe_handler(int sig) } #endif -bool use_ipv6=FALSE; -unsigned short port = DEFAULT_PORT; -unsigned short connectport = 0; /* if non-zero, we activate this mode */ - -enum sockmode { - PASSIVE_LISTEN, /* as a server waiting for connections */ - PASSIVE_CONNECT, /* as a server, connected to a client */ - ACTIVE, /* as a client, connected to a server */ - ACTIVE_DISCONNECT /* as a client, disconnected from server */ -}; - /* sockfdp is a pointer to an established stream or CURL_SOCKET_BAD @@ -519,7 +519,6 @@ int main(int argc, char *argv[]) #endif /* ENABLE_IPV6 */ curl_socket_t sock; curl_socket_t msgsock; - FILE *pidfile; char *pidname= (char *)".sockfilt.pid"; int rc; int error; @@ -682,18 +681,7 @@ int main(int argc, char *argv[]) else logmsg("Listening on port %d", port); - pidfile = fopen(pidname, "w"); - if(pidfile) { - long pid = (long)getpid(); - fprintf(pidfile, "%ld\n", pid); - fclose(pidfile); - logmsg("Wrote pid %ld to %s", pid, pidname); - } - else { - error = ERRNO; - logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", pidname); - logmsg("Couldn't write pid file"); + if(!write_pidfile(pidname)) { sclose(sock); return 1; } |