Browse code

- applied pgid patch from Jan (save pgdid in the file specified by -G) - inc ver no

Andrei Pelinescu-Onciul authored on 03/05/2004 10:29:57
Showing 4 changed files
... ...
@@ -45,7 +45,7 @@ export makefile_defs
45 45
 VERSION = 0
46 46
 PATCHLEVEL = 8
47 47
 SUBLEVEL =   13
48
-EXTRAVERSION = -dev-28
48
+EXTRAVERSION = -dev-29
49 49
 
50 50
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
51 51
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -31,8 +31,12 @@
31 31
  *  2004-02-20  removed from ser main.c into its own file (andrei)
32 32
  *  2004-03-04  moved setuid/setgid in do_suid() (andrei)
33 33
  *  2004-03-25  added increase_open_fds & set_core_dump (andrei)
34
+ *  2004-04-04  applied pgid patch from janakj
34 35
  */
35 36
 
37
+#define _XOPEN_SOURCE
38
+#define _XOPEN_SOURCE_EXTENDED
39
+
36 40
 #include <sys/types.h>
37 41
 #include <unistd.h>
38 42
 #include <signal.h>
... ...
@@ -127,6 +131,27 @@ int daemonize(char*  name)
127 127
 			fclose(pid_stream);
128 128
 		}
129 129
 	}
130
+
131
+	if (pgid_file!=0){
132
+		if ((pid_stream=fopen(pgid_file, "r"))!=NULL){
133
+			fscanf(pid_stream, "%d", &p);
134
+			fclose(pid_stream);
135
+			if (p==-1){
136
+				LOG(L_CRIT, "pgid file %s exists, but doesn't contain a valid"
137
+				    " pgid number\n", pgid_file);
138
+				goto error;
139
+			}
140
+		}
141
+		pid=getpgid(0);
142
+		if ((pid_stream=fopen(pgid_file, "w"))==NULL){
143
+			LOG(L_WARN, "unable to create pgid file %s: %s\n",
144
+			    pgid_file, strerror(errno));
145
+			goto error;
146
+		}else{
147
+			fprintf(pid_stream, "%i\n", (int)pid);
148
+			fclose(pid_stream);
149
+		}
150
+	}
130 151
 	
131 152
 	/* try to replace stdin, stdout & stderr with /dev/null */
132 153
 	if (freopen("/dev/null", "r", stdin)==0){
... ...
@@ -51,6 +51,7 @@ extern unsigned short port_no;
51 51
 extern int uid;
52 52
 extern int gid;
53 53
 char* pid_file;
54
+char* pgid_file;
54 55
 extern int own_pgid; /* whether or not we have our own pgid (and it's ok
55 56
 >--->--->--->--->--->--->--->--->--->--->--- to use kill(0, sig) */
56 57
 
... ...
@@ -237,6 +237,7 @@ Options:\n\
237 237
     -u uid       Change uid \n\
238 238
     -g gid       Change gid \n\
239 239
     -P file      Create a pid file\n\
240
+    -G file      Create a pgid file\n\
240 241
     -i fifo_path Create a fifo (usefull for monitoring " NAME ") \n\
241 242
     -x socket    Create a unix domain socket \n"
242 243
 #ifdef STATS
... ...
@@ -405,7 +406,7 @@ extern int yyparse();
405 405
 int is_main=1; /* flag = is this the  "main" process? */
406 406
 
407 407
 char* pid_file = 0; /* filename as asked by use */
408
-
408
+char* pgid_file = 0;
409 409
 
410 410
 
411 411
 /* callit before exiting; if show_status==1, mem status is displayed */
... ...
@@ -440,6 +441,7 @@ void cleanup(show_status)
440 440
 	shm_mem_destroy();
441 441
 #endif
442 442
 	if (pid_file) unlink(pid_file);
443
+	if (pgid_file) unlink(pgid_file);
443 444
 }
444 445
 
445 446
 
... ...
@@ -1125,7 +1127,7 @@ int main(int argc, char** argv)
1125 1125
 #ifdef STATS
1126 1126
 	"s:"
1127 1127
 #endif
1128
-	"f:cp:m:b:l:n:N:rRvdDETVhw:t:u:g:P:i:x:";
1128
+	"f:cp:m:b:l:n:N:rRvdDETVhw:t:u:g:P:G:i:x:";
1129 1129
 	
1130 1130
 	while((c=getopt(argc,argv,options))!=-1){
1131 1131
 		switch(c){
... ...
@@ -1248,6 +1250,9 @@ int main(int argc, char** argv)
1248 1248
 			case 'P':
1249 1249
 					pid_file=optarg;
1250 1250
 					break;
1251
+		        case 'G':
1252
+				        pgid_file=optarg;
1253
+				        break;
1251 1254
 			case 'i':
1252 1255
 					fifo=optarg;
1253 1256
 					break;