1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
Description: fixes the pidfile option
Author: Rene Mayorga <rmayorga@debian.org.sv>
Last-Update: 2008-09-30
Author: Martin Steghöfer <martin@steghoefer.eu>
Bug-Debian: https://bugs.debian.org/715633
Last-Update: 2014-08-22
Index: ample/src/ample.c
===================================================================
--- ample.orig/src/ample.c
+++ ample/src/ample.c
@@ -241,6 +241,26 @@ sighup_handler(int signal)
return;
}
+/*
+ * Write a pidfile
+ *
+ * Added by Debian Maintainer
+ *
+ */
+static int
+do_pidfile(void)
+{
+ FILE *f;
+ int pidnum;
+ pidnum = getpid();
+ f = fopen(gconf.pidfile, "w");
+ if (!f) {
+ return (1);
+ }
+ fprintf(f,"%d\n", pidnum);
+ fclose(f);
+ return(0);
+}
/*
* Checks if a file descriptor is a socket.
@@ -292,6 +312,15 @@ daemonize()
die("fork");
}
+/* Remove pidfile when dies
+ *
+ */
+static void
+removepidfile(void)
+{
+ unlink(gconf.pidfile);
+ exit(EXIT_SUCCESS);
+}
/*
* Prepares the proper way for ample to log messages.
@@ -460,6 +489,18 @@ main(int argc, char *argv[])
checkopt(argc, argv);
gconf.inetd = issocket(0);
daemonize();
+
+ /* Added by Debian Maintainer */
+ if (gconf.pidfile) {
+ debug (1, "pidfile:%s \n", gconf.pidfile);
+ if (do_pidfile() != 0) {
+ debug(1, "could not write pidfile");
+ exit(1);
+ }
+
+ }
+ /**/
+
preparelog();
if(!gconf.inetd)
logmsg("Ample/%s started\n", AMPLE_VERSION);
@@ -488,6 +529,12 @@ main(int argc, char *argv[])
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sigchild_handler;
sigaction(SIGCHLD, &sa, NULL);
+
+ /* Added by the Debian Maintainer */
+ if (signal(SIGTERM, removepidfile) == SIG_ERR) {
+ debug(1, "err, I can't quit");
+ }
+ /**/
sigemptyset(&chld);
sigaddset(&chld, SIGCHLD);
Index: ample/src/ample.h
===================================================================
--- ample.orig/src/ample.h
+++ ample/src/ample.h
@@ -36,6 +36,7 @@ struct global_config {
char * servername;
char * serveraddress;
char * filter;
+ char * pidfile;
};
struct childstat {
Index: ample/src/configuration.c
===================================================================
--- ample.orig/src/configuration.c
+++ ample/src/configuration.c
@@ -621,6 +621,7 @@ setconfopt(int argc, char * argv[]) {
{"servername", OPT_STRING, &gconf.servername},
{"serveraddress", OPT_STRING, &gconf.serveraddress},
{"username", OPT_STRING, &gconf.username},
+ {"pidfile", OPT_STRING, &gconf.pidfile},
{NULL, 0, NULL}
};
@@ -674,13 +675,14 @@ setcmdopt(int argc, char * argv[])
{"debug", optional_argument, NULL, 'd'},
{"trace", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'v'},
+ {"pidfile", required_argument, NULL, 'i'},
{NULL, 0, NULL, 0}
};
- while((c = getopt_long(argc, argv, "p:oc:nf:m:hd::tv", longopts, &i))
+ while((c = getopt_long(argc, argv, "p:oc:nf:m:hd::ti:v", longopts, &i))
!= -1) {
#else
- while((c = getopt(argc, argv, "p:oc:nf:m:hd::tv")) != -1) {
+ while((c = getopt(argc, argv, "p:oc:nf:m:hd::ti:v")) != -1) {
#endif
switch(c) {
case 'p':
@@ -718,6 +720,9 @@ setcmdopt(int argc, char * argv[])
case 'v':
printf("Ample version %s\n", AMPLE_VERSION);
exit(0);
+ case 'i':
+ gconf.pidfile = strdup(optarg);
+ break;
default:
usage(TRUE);
}
Index: ample/src/configuration.h
===================================================================
--- ample.orig/src/configuration.h
+++ ample/src/configuration.h
@@ -70,6 +70,7 @@ the option -t).\n\
higher number means more detail\n\
-t, --trace no forking, no backgrounding\n\
helpful when debugging\n\
+ -i, --pidfile create a pidfile \n\
-v, --version output version information and exit\n\
\n\
Report bugs to <david@2gen.com>\n"
@@ -86,7 +87,8 @@ Report bugs to <david@2gen.com>\n"
-d[=NUMBER] debug messages will be printed,\n\
higher number means more detail\n\
-t no forking, no backgrounding,\n\
- helpful when debugging)\n\
+ (helpful when debugging)\n\
+ -i create a pidfile \n\
-v output version information and exit\n\
\n\
Report bugs to <david@2gen.com>\n"
Index: ample/docs/ample.1.in
===================================================================
--- ample.orig/docs/ample.1.in
+++ ample/docs/ample.1.in
@@ -86,6 +86,9 @@ Disables forking and backgrounding, usef
.B -v --version
Display version information and exit.
.TP
+.B -i --pidfile [PIDFILE]
+Write a PIDFILE to handle ample as a daemon
+.TP
.BI "[" "PATH" "...]"
These are path(s) to files or directories that Ample can use to
populate it's list of MP3's. If
|