Skip to content

Commit 9bd5fa6

Browse files
committed
Delete dead code from lib.misc.c.
1 parent 761f323 commit 9bd5fa6

File tree

2 files changed

+0
-155
lines changed

2 files changed

+0
-155
lines changed

lib/lib.misc.c

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,6 @@
2424

2525
const int def_stdio_fd[3] = { STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO };
2626

27-
void _alert(const char *libdir, const char *msgtype, const char *description)
28-
{
29-
static char none[1] = "";
30-
char *cmd;
31-
int silenced __attribute__((unused));
32-
33-
if ( description==NULL ) description = none;
34-
35-
cmd = allocstr("%s/alert '%s' '%s' &",libdir,msgtype,description);
36-
logmsg(LOG_INFO,"executing '%s'",cmd);
37-
38-
/* Assign return value to temp variable to remove compiler
39-
* warnings. We're already trying to generate a warning; there's
40-
* no sense in generating another warning when this gives an
41-
* error.
42-
*/
43-
silenced = system(cmd);
44-
45-
free(cmd);
46-
}
47-
4827
int execute(const char *cmd, const char **args, int nargs, int stdio_fd[3], int err2out)
4928
{
5029
pid_t pid, child_pid;
@@ -143,112 +122,6 @@ int execute(const char *cmd, const char **args, int nargs, int stdio_fd[3], int
143122
return -1;
144123
}
145124

146-
int exitsignalled;
147-
148-
void sig_handler(int sig)
149-
{
150-
logmsg(LOG_DEBUG, "Signal %d received", sig);
151-
152-
switch ( sig ) {
153-
case SIGTERM:
154-
case SIGHUP:
155-
case SIGINT:
156-
exitsignalled = 1;
157-
break;
158-
}
159-
}
160-
161-
void initsignals()
162-
{
163-
struct sigaction sa;
164-
sigset_t newmask, oldmask;
165-
166-
exitsignalled = 0;
167-
168-
/* unmask all signals */
169-
memset(&newmask, 0, sizeof(newmask));
170-
if ( sigprocmask(SIG_SETMASK, &newmask, &oldmask)!=0 ) {
171-
error(errno,"unmasking signals");
172-
}
173-
174-
logmsg(LOG_DEBUG, "Installing signal handlers");
175-
176-
sa.sa_handler = &sig_handler;
177-
sa.sa_mask = newmask;
178-
sa.sa_flags = 0;
179-
180-
if ( sigaction(SIGTERM,&sa,NULL)!=0 ) error(errno,"installing signal handler");
181-
if ( sigaction(SIGHUP ,&sa,NULL)!=0 ) error(errno,"installing signal handler");
182-
if ( sigaction(SIGINT ,&sa,NULL)!=0 ) error(errno,"installing signal handler");
183-
}
184-
185-
186-
char *pidfile;
187-
188-
/* Function to remove PID file at process exit. */
189-
void remove_pidfile()
190-
{
191-
unlink(pidfile);
192-
}
193-
194-
void daemonize(const char *_pidfile)
195-
{
196-
pid_t pid;
197-
int fd, maxfd;
198-
char str[15];
199-
200-
switch ( pid = fork() ) {
201-
case -1: error(errno, "cannot fork daemon");
202-
case 0: break; /* child process: do nothing here. */
203-
default: _exit(0); /* parent process: exit. */
204-
}
205-
206-
/* Check and write PID to file */
207-
if ( _pidfile!=NULL ) {
208-
pidfile = strdup(_pidfile);
209-
if ( (fd=open(pidfile, O_RDWR|O_CREAT|O_EXCL, 0640))<0 ) {
210-
error(errno, "cannot create pidfile '%s'", pidfile);
211-
}
212-
sprintf(str, "%d\n", pid);
213-
if ( write(fd, str, strlen(str))<(ssize_t)strlen(str) ) {
214-
error(errno, "failed writing PID to file");
215-
}
216-
if ( close(fd)!=0 ) error(errno, "closing pidfile '%s'", pidfile);
217-
atexit(remove_pidfile);
218-
}
219-
220-
/* Notify user with daemon PID before detaching from TTY. */
221-
logmsg(LOG_NOTICE, "daemonizing with PID = %d", pid);
222-
223-
/* Reopen std{in,out,err} file descriptors to /dev/null.
224-
Closing them gives error when the daemon or a child process
225-
tries to read/write to them. */
226-
if ( freopen("/dev/null", "r", stdin )!=NULL ||
227-
freopen("/dev/null", "w", stdout)!=NULL ||
228-
freopen("/dev/null", "w", stderr)!=NULL ) {
229-
error(errno, "cannot reopen stdio files to /dev/null");
230-
}
231-
232-
/* Close all other file descriptors. */
233-
maxfd = sysconf(_SC_OPEN_MAX);
234-
for(fd=3; fd<maxfd; fd++) close(fd);
235-
236-
/* Start own process group, detached from any tty */
237-
if ( setsid()<0 ) error(errno, "cannot set daemon process group");
238-
}
239-
240-
char *stripendline(char *str)
241-
{
242-
size_t i, j;
243-
244-
for(i=0, j=0; str[i]!=0; i++) {
245-
if ( ! (str[i]=='\n' || str[i]=='\r') ) str[j++] = str[i];
246-
}
247-
248-
str[j] = 0;
249-
250-
return str;
251-
}
252125

253126
void version(const char *prog, const char *vers)
254127
{

lib/lib.misc.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ extern "C" {
1717
* LIBDIR as defined in calling program. */
1818
#define alert(msgtype,description) _alert(LIBDIR,msgtype,description)
1919

20-
void _alert(const char *libdir, const char *msgtype, const char *description)
21-
__attribute__((nonnull (1, 2)));
22-
/* Execute 'alert' plugin program to perform user configurable action
23-
* on important system events. See default alert script for more details.
24-
*/
25-
2620
int execute(const char *, const char **, int, int[3], int)
2721
__attribute__((nonnull (1, 2)));
2822
/* Execute a subprocess using fork and execvp and optionally perform
@@ -53,28 +47,6 @@ int execute(const char *, const char **, int, int[3], int)
5347
* with the process-ID of the child command.
5448
*/
5549

56-
void initsignals();
57-
/* Installs a signal handler to gracefully terminate daemon programs
58-
* upon receiving TERMINATE, HANGUP and INTERRUPT signals which sets
59-
* 'extern int exitsignalled = 1'. The sleep() call will automatically
60-
* return on receiving a signal.
61-
*/
62-
63-
void daemonize(const char *);
64-
/* Forks and detaches the current process to run as a daemon. Similar
65-
* to the daemon() call present in Linux and *BSD, but implemented here,
66-
* because it is not specified by POSIX, SUSv2 or SVr4.
67-
*
68-
* Arguments:
69-
* char *pidfile pidfile to check for running instances and write PID;
70-
* set to NULL to not use a pidfile.
71-
*
72-
* Either returns successfully or exits with an error.
73-
*/
74-
75-
char *stripendline(char *) __attribute__((nonnull (1)));
76-
/* Removes end-of-line characters (CR and LF) from string. Returns the
77-
* original pointer to the modified string. */
7850

7951
void version(const char *, const char *) __attribute__((nonnull (1, 2)));
8052
/* Print standard program name and version, with disclaimer and GPL

0 commit comments

Comments
 (0)