From a3b299c24db7c7a271f4a9170d441e46862342e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Fri, 4 Aug 2006 08:54:36 +0000 Subject: [PATCH] Error handling due to pidfile creation. Close connection after each soap request (should fix insane close connection behaviour). --- org.glite.jp.index/src/bones_server.c | 2 +- org.glite.jp.index/src/common_server.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/org.glite.jp.index/src/bones_server.c b/org.glite.jp.index/src/bones_server.c index 7756e08..71cdf6f 100644 --- a/org.glite.jp.index/src/bones_server.c +++ b/org.glite.jp.index/src/bones_server.c @@ -365,7 +365,7 @@ int request(int conn,struct timeval *to,void *data) } glite_jp_run_deferred(ctx); - return 0; + return ENOTCONN; } static int reject(int conn) diff --git a/org.glite.jp.index/src/common_server.c b/org.glite.jp.index/src/common_server.c index 63052b4..a815293 100644 --- a/org.glite.jp.index/src/common_server.c +++ b/org.glite.jp.index/src/common_server.c @@ -40,12 +40,12 @@ int glite_jpis_daemonize(const char *servername, const char *custom_pidfile, con if (!custom_pidfile) { asprintf(&pidfile, "%s/%s.pid", geteuid() == 0 ? "/var/run" : getenv("HOME"), servername); } else { - pidfile = NULL; + pidfile = strdup(custom_pidfile); } // printf("pidfile: %s\n", pidfile ? pidfile : custom_pidfile); setpgrp(); /* needs for signalling */ master = getpid(); - fpid = fopen(pidfile ? pidfile : custom_pidfile,"r"); + fpid = fopen(pidfile,"r"); if ( fpid ) { opid = -1; @@ -60,13 +60,16 @@ int glite_jpis_daemonize(const char *servername, const char *custom_pidfile, con else if (errno != ESRCH) { perror("kill()"); return 0; } } fclose(fpid); - } else if (errno != ENOENT) { perror(pidfile ? pidfile : custom_pidfile); free(pidfile); return 0; } + } else if (errno != ENOENT) { perror(pidfile); free(pidfile); return 0; } - fpid = fopen(pidfile ? pidfile : custom_pidfile, "w"); - if (!fpid) { perror(pidfile ? pidfile : custom_pidfile); free(pidfile); return 0; } - free(pidfile); - fprintf(fpid, "%d", getpid()); - fclose(fpid); + if (((fpid = fopen(pidfile, "w")) == NULL) || + (fprintf(fpid, "%d", getpid()) <= 0) || + (fclose(fpid) != 0)) { + perror(pidfile); + free(pidfile); + return 0; + } + free(pidfile); return 1; } -- 1.8.2.3