mirror of
https://github.com/shadow-maint/shadow.git
synced 2026-01-29 15:24:12 +00:00
Accessing and setting shadow_progname is not as straight-forward as it might seem due to the way of linking libshadow_la with libsubid and programs. Enforce the usage of log_get_progname to make this less messy. With last entry of shadowlog_internal.h gone, remove the file entirely. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
67 lines
1.4 KiB
C
67 lines
1.4 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2011 , Jonathan Nieder
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
|
|
#include "exitcodes.h"
|
|
#include "prototypes.h"
|
|
#include "shadowlog.h"
|
|
#include "string/strerrno.h"
|
|
|
|
|
|
int
|
|
run_command(const char *cmd, const char *argv[],
|
|
/*@null@*/const char *envp[], int *restrict status)
|
|
{
|
|
pid_t pid, wpid;
|
|
|
|
if (NULL == envp) {
|
|
envp = (const char **)environ;
|
|
}
|
|
|
|
(void) fflush (stdout);
|
|
(void) fflush (log_get_logfd());
|
|
|
|
pid = fork ();
|
|
if (0 == pid) {
|
|
(void) execve (cmd, (char * const *) argv,
|
|
(char * const *) envp);
|
|
if (ENOENT == errno) {
|
|
_exit (E_CMD_NOTFOUND);
|
|
}
|
|
fprintf (log_get_logfd(), "%s: cannot execute %s: %s\n",
|
|
log_get_progname(), cmd, strerrno());
|
|
_exit (E_CMD_NOEXEC);
|
|
} else if ((pid_t)-1 == pid) {
|
|
fprintf (log_get_logfd(), "%s: cannot execute %s: %s\n",
|
|
log_get_progname(), cmd, strerrno());
|
|
return -1;
|
|
}
|
|
|
|
do {
|
|
wpid = waitpid (pid, status, 0);
|
|
if ((pid_t)-1 == wpid && errno == ECHILD)
|
|
break;
|
|
} while ( ((pid_t)-1 == wpid && errno == EINTR)
|
|
|| ((pid_t)-1 != wpid && wpid != pid));
|
|
|
|
if ((pid_t)-1 == wpid) {
|
|
fprintf (log_get_logfd(), "%s: waitpid (status: %d): %s\n",
|
|
log_get_progname(), *status, strerrno());
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|