Allow time for pidfiles to be created, #178274.

Use int instead of char for getopt, #178084 thanks to drizztbsd.
This commit is contained in:
Roy Marples 2007-05-14 12:24:18 +00:00
parent 86c7d44d66
commit 0942916b72
7 changed files with 46 additions and 26 deletions

View File

@ -1,6 +1,11 @@
# ChangeLog for Gentoo System Intialization ("rc") scripts # ChangeLog for Gentoo System Intialization ("rc") scripts
# Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2 # Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2
14 May 2007; Roy Marples <uberlord@gentoo.org>:
Allow time for pidfiles to be created, #178274.
Use int instead of char for getopt, #178084 thanks to drizztbsd.
11 May 2007; Roy Marples <uberlord@gentoo.org>: 11 May 2007; Roy Marples <uberlord@gentoo.org>:
Store the defined random pool size, #177722 thanks to Yaroslav Isakov. Store the defined random pool size, #177722 thanks to Yaroslav Isakov.

View File

@ -70,7 +70,7 @@ LDLIBS_RS = -ldl
override CPPFLAGS += -D_GNU_SOURCE override CPPFLAGS += -D_GNU_SOURCE
endif endif
ifeq ($(OS),BSD) ifeq ($(OS),BSD)
override LDLIBS += -lkvm LDLIBS_LIBRC = -lkvm
endif endif
HAVE_PAM = HAVE_PAM =
@ -102,7 +102,7 @@ $(LIBEINFOSO): $(LIBEINFOOBJS)
$(LIBRCOBJS): CFLAGS += -fPIC $(LIBRCOBJS): CFLAGS += -fPIC
$(LIBRCSO): $(LIBRCOBJS) $(LIBRCSO): $(LIBRCOBJS)
$(CC) -fPIC -shared -Wl,-soname,$(LIBRCSO) -o $(LIBRCSO) $(LIBRCOBJS) $(CC) -fPIC -shared -Wl,-soname,$(LIBRCSO) -o $(LIBRCSO) $(LDLIBS_LIBRC) $(LIBRCOBJS)
ln -sf $(LIBRCSO) librc.so ln -sf $(LIBRCSO) librc.so
env-update: $(LIBEINFOSO) $(LIBRCSO) env-update.o env-update: $(LIBEINFOSO) $(LIBRCSO) env-update.o

View File

@ -78,15 +78,15 @@ int main (int argc, char **argv)
int result = EXIT_FAILURE; int result = EXIT_FAILURE;
char *token; char *token;
int n = 0; int n = 0;
char c; int opt;
while ((c = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
{ {
#ifdef HAVE_GETMNTENT #ifdef HAVE_GETMNTENT
fp = setmntent ("/etc/fstab", "r"); fp = setmntent ("/etc/fstab", "r");
#endif #endif
switch (c) { switch (opt) {
case 'f': case 'f':
while ((token = strsep (&optarg, ","))) while ((token = strsep (&optarg, ",")))
while ((ent = GET_ENT)) while ((ent = GET_ENT))

View File

@ -157,11 +157,11 @@ int main (int argc, char **argv)
bool list_fstype = false; bool list_fstype = false;
bool reverse = false; bool reverse = false;
char **mounts = NULL; char **mounts = NULL;
char c; int opt;
while ((c = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
switch (c) { switch (opt) {
case 'F': case 'F':
if (fstype_regex) if (fstype_regex)
free (fstype_regex); free (fstype_regex);

View File

@ -70,13 +70,12 @@ int main (int argc, char **argv)
char **services = NULL; char **services = NULL;
char *level; char *level;
char *service; char *service;
char c; int opt;
int option_index = 0;
int i; int i;
int j; int j;
while ((c = getopt_long(argc, argv, getoptstring, longopts, &option_index)) != -1) while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1)
switch (c) { switch (opt) {
case 'a': case 'a':
levels = rc_get_runlevels (); levels = rc_get_runlevels ();
break; break;

View File

@ -972,7 +972,7 @@ int main (int argc, char **argv)
bool doneone = false; bool doneone = false;
char pid[16]; char pid[16];
int retval; int retval;
char c; int opt;
service = argv[1]; service = argv[1];
/* Show help if insufficient args */ /* Show help if insufficient args */
@ -1079,9 +1079,9 @@ int main (int argc, char **argv)
argv++; argv++;
/* Right then, parse any options there may be */ /* Right then, parse any options there may be */
while ((c = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
switch (c) { switch (opt) {
case 'd': case 'd':
setenv ("RC_DEBUG", "yes", 1); setenv ("RC_DEBUG", "yes", 1);
break; break;

View File

@ -500,7 +500,7 @@ int main (int argc, char **argv)
{ "stderr", 1, NULL, '2'}, { "stderr", 1, NULL, '2'},
{ NULL, 0, NULL, 0} { NULL, 0, NULL, 0}
}; };
int c; int opt;
bool start = false; bool start = false;
bool stop = false; bool stop = false;
bool oknodo = false; bool oknodo = false;
@ -541,10 +541,10 @@ int main (int argc, char **argv)
if (sscanf (env, "%d", &nicelevel) != 1) if (sscanf (env, "%d", &nicelevel) != 1)
eerror ("%s: invalid nice level `%s' (SSD_NICELEVEL)", progname, env); eerror ("%s: invalid nice level `%s' (SSD_NICELEVEL)", progname, env);
while ((c = getopt_long (argc, argv, while ((opt = getopt_long (argc, argv,
"KN:R:Sbc:d:g:mn:op:qs:tu:r:vx:1:2:", "KN:R:Sbc:d:g:mn:op:qs:tu:r:vx:1:2:",
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
switch (c) { switch (opt) {
case 'K': /* --stop */ case 'K': /* --stop */
stop = true; stop = true;
break; break;
@ -962,6 +962,7 @@ int main (int argc, char **argv)
if (START_WAIT > 0) { if (START_WAIT > 0) {
struct timeval stopat; struct timeval stopat;
struct timeval now; struct timeval now;
bool retestpid = false;
if (gettimeofday (&stopat, NULL) != 0) if (gettimeofday (&stopat, NULL) != 0)
eerrorx ("%s: gettimeofday: %s", progname, strerror (errno)); eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
@ -991,11 +992,20 @@ int main (int argc, char **argv)
if (kill (pid, 0) == 0) if (kill (pid, 0) == 0)
alive = true; alive = true;
} else { } else {
if (pidfile && rc_exists (pidfile)) { if (pidfile) {
if (do_stop (NULL, NULL, pidfile, uid, 0, true, false, true) > 0) /* The pidfile may not have been written yet - give it some time */
if (get_pid (pidfile, true) == -1) {
alive = true; alive = true;
retestpid = true;
} else { } else {
if (do_stop (exec, cmd, NULL, uid, 0, true, false, true) > 0) retestpid = false;
if (do_stop (NULL, NULL, pidfile, uid, 0,
true, false, true) > 0)
alive = true;
}
} else {
if (do_stop (exec, cmd, NULL, uid, 0, true, false, true)
> 0)
alive = true; alive = true;
} }
} }
@ -1006,6 +1016,12 @@ int main (int argc, char **argv)
if (timercmp (&now, &stopat, >)) if (timercmp (&now, &stopat, >))
break; break;
} }
if (retestpid) {
if (do_stop (NULL, NULL, pidfile, uid, 0, true,
false, true) < 1)
eerrorx ("%s: %s died", progname, exec);
}
} }
if (svcname) if (svcname)