KNF
Formatter: knfmt 4.2.0 Signed-off-by: Masanori Ogino <mogino@acm.org>
This commit is contained in:
parent
6751cd55df
commit
18181c8b02
1 changed files with 34 additions and 38 deletions
64
main.c
64
main.c
|
|
@ -46,14 +46,14 @@
|
||||||
#include "Const.h"
|
#include "Const.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
extern int fork_flag;
|
extern int fork_flag;
|
||||||
extern char *lock_file;
|
extern char *lock_file;
|
||||||
|
|
||||||
char *version_number = "2.08C";
|
char *version_number = "2.08C";
|
||||||
char *time_stamp = "Mon Mar 23 16:42:59 JST 1998";
|
char *time_stamp = "Mon Mar 23 16:42:59 JST 1998";
|
||||||
|
|
||||||
static void
|
static void
|
||||||
opening (void)
|
opening(void)
|
||||||
{
|
{
|
||||||
printf("Kana-Kanji Conversion Server Version %s\r\n", version_number);
|
printf("Kana-Kanji Conversion Server Version %s\r\n", version_number);
|
||||||
printf("Copyright (c) 1990-1995 Sony Corporation\r\n");
|
printf("Copyright (c) 1990-1995 Sony Corporation\r\n");
|
||||||
|
|
@ -62,34 +62,33 @@ opening (void)
|
||||||
|
|
||||||
#ifdef LOCK_FILE
|
#ifdef LOCK_FILE
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
make_lockfile (void)
|
make_lockfile(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(lock_file, O_CREAT | O_EXCL, 0600);
|
fd = open(lock_file, O_CREAT | O_EXCL, 0600);
|
||||||
if (fd < 0) return ERROR;
|
if (fd < 0)
|
||||||
|
return ERROR;
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
erase_lockfile (void)
|
erase_lockfile(void)
|
||||||
{
|
{
|
||||||
return unlink(lock_file);
|
return unlink(lock_file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
signal_handler (int sig)
|
signal_handler(int sig)
|
||||||
{
|
{
|
||||||
warning_out("signal %d catched.", sig);
|
warning_out("signal %d catched.", sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
terminate_handler (int sig)
|
terminate_handler(int sig)
|
||||||
{
|
{
|
||||||
close_socket();
|
close_socket();
|
||||||
sj_closeall();
|
sj_closeall();
|
||||||
|
|
@ -100,7 +99,7 @@ terminate_handler (int sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
server_terminate (void)
|
server_terminate(void)
|
||||||
{
|
{
|
||||||
close_socket();
|
close_socket();
|
||||||
sj_closeall();
|
sj_closeall();
|
||||||
|
|
@ -110,8 +109,8 @@ server_terminate (void)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
exec_fork (void)
|
exec_fork(void)
|
||||||
{
|
{
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
|
|
@ -119,11 +118,10 @@ exec_fork (void)
|
||||||
if (tmp < 0) {
|
if (tmp < 0) {
|
||||||
fprintf(stderr, "Can't fork child process\r\n");
|
fprintf(stderr, "Can't fork child process\r\n");
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
signal(SIGCHLD, _exit);
|
signal(SIGCHLD, _exit);
|
||||||
signal(SIGHUP , SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
signal(SIGINT , SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
signal(SIGQUIT, SIG_IGN);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
signal(SIGTSTP, SIG_IGN);
|
signal(SIGTSTP, SIG_IGN);
|
||||||
signal(SIGTERM, _exit);
|
signal(SIGTERM, _exit);
|
||||||
|
|
@ -132,30 +130,28 @@ exec_fork (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGHUP, (void (*)())signal_handler);
|
signal(SIGHUP, (void (*)())signal_handler);
|
||||||
|
|
||||||
|
signal(SIGINT, (void (*)())terminate_handler);
|
||||||
signal(SIGINT, (void (*)())terminate_handler);
|
|
||||||
signal(SIGQUIT, (void (*)())signal_handler);
|
signal(SIGQUIT, (void (*)())signal_handler);
|
||||||
signal(SIGTERM, (void (*)())terminate_handler);
|
signal(SIGTERM, (void (*)())terminate_handler);
|
||||||
if (fork_flag)
|
if (fork_flag)
|
||||||
signal(SIGTSTP, SIG_IGN);
|
signal(SIGTSTP, SIG_IGN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
leave_tty(void)
|
||||||
static void
|
|
||||||
leave_tty (void)
|
|
||||||
{
|
{
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
tmp = open_error();
|
tmp = open_error();
|
||||||
tmp |= open_log();
|
tmp |= open_log();
|
||||||
tmp |= open_debug();
|
tmp |= open_debug();
|
||||||
kill(getppid(), SIGTERM);
|
kill(getppid(), SIGTERM);
|
||||||
fclose(stdin);
|
fclose(stdin);
|
||||||
fclose(stdout);
|
fclose(stdout);
|
||||||
if (!tmp) fclose(stderr);
|
if (!tmp)
|
||||||
|
fclose(stderr);
|
||||||
|
|
||||||
if (fork_flag) {
|
if (fork_flag) {
|
||||||
if ((tmp = open("/dev/tty", O_RDWR)) >= 0) {
|
if ((tmp = open("/dev/tty", O_RDWR)) >= 0) {
|
||||||
|
|
@ -166,15 +162,14 @@ leave_tty (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
opening();
|
opening();
|
||||||
#ifndef __NetBSD__
|
#ifndef __NetBSD__
|
||||||
if (setuid(geteuid())) {
|
if (setuid(geteuid())) {
|
||||||
fprintf(stderr, "error at setuid.\r\n"); exit(1);
|
fprintf(stderr, "error at setuid.\r\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -184,7 +179,8 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
#ifdef LOCK_FILE
|
#ifdef LOCK_FILE
|
||||||
if (make_lockfile() == ERROR) {
|
if (make_lockfile() == ERROR) {
|
||||||
fprintf(stderr, "Already running...\r\n"); exit(1);
|
fprintf(stderr, "Already running...\r\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -193,7 +189,7 @@ main (int argc, char **argv)
|
||||||
socket_init();
|
socket_init();
|
||||||
open_socket();
|
open_socket();
|
||||||
|
|
||||||
leave_tty();
|
leave_tty();
|
||||||
|
|
||||||
preload_dict();
|
preload_dict();
|
||||||
preopen_dict();
|
preopen_dict();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue