Import ncpfs 0.17

This commit is contained in:
ncpfs archive import
2026-04-28 20:39:57 +02:00
parent 5753870858
commit 1fa124bd7c
36 changed files with 1594 additions and 226 deletions

View File

@@ -9,10 +9,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <signal.h>
#include "ncplib.h"
@@ -77,26 +79,29 @@ terminate_handler()
term_request=1;
}
static void
daemonize()
/* Daemon_init is taken from Stevens, Adv. Unix programming */
static int
daemon_init(void)
{
int fd,c;
if ((c = fork()) > 0) exit(0);
if (c < 0)
{
fprintf(stderr, "ipxripd: can't fork: %s\n",strerror(errno));
exit(1);
pid_t pid;
if ((pid = fork()) < 0)
{
return -1;
}
else if (pid != 0)
{
exit(0); /* parent vanishes */
}
/* child process */
setsid();
chdir("/");
umask(0);
close(0);
close(1);
close(2);
if ((fd = open("/dev/tty", O_RDWR)) >= 0)
{
ioctl(fd, TIOCNOTTY, NULL);
close(fd);
}
return 0;
}
int
@@ -137,12 +142,13 @@ main(int argc, char *argv[])
if (debug == 0)
{
daemonize();
daemon_init();
openlog("pserver", LOG_PID, LOG_LPR);
}
if (ncp_initialize_as(&conn, &argc, argv, 1, NCP_BINDERY_PSERVER) != 0)
{
perror("Could not open connection");
perror("Could not open connection");
return 1;
}
@@ -268,13 +274,13 @@ poll_queue(struct nw_queue *q)
if (pipe(fd) < 0)
{
perror("pipe");
syslog(LOG_ERR, "pipe error: %m");
goto fail;
}
if ((pid = fork()) < 0)
{
perror("fork");
syslog(LOG_ERR, "fork error: %m");
goto fail;
}
@@ -301,7 +307,7 @@ poll_queue(struct nw_queue *q)
if (waitpid(pid, NULL, 0) < 0)
{
perror("waitpid");
syslog(LOG_ERR, "waitpid: %m\n");
}
}
else
@@ -314,7 +320,7 @@ poll_queue(struct nw_queue *q)
{
if (dup2(fd[0], STDIN_FILENO) != STDIN_FILENO)
{
perror("dup2");
syslog(LOG_ERR, "dup2 error: %m\n");
close(fd[0]);
exit(1);
}
@@ -322,7 +328,7 @@ poll_queue(struct nw_queue *q)
}
execl("/bin/sh", "sh", "-c", q->command, NULL);
perror("exec");
syslog(LOG_ERR, "exec error: %m\n");
close(fd[0]);
exit(1);
}