Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Per Cederqvist
lyskom-server-ceder-1616-generations-topgit
Commits
91c1f397
Commit
91c1f397
authored
Mar 06, 1994
by
Per Cederqvist
Browse files
First try as a C program.
parent
2fff1f72
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/server/updateLysKOM.c
0 → 100644
View file @
91c1f397
/*
* $Id: updateLysKOM.c,v 1.1 1994/03/06 19:59:55 ceder Exp $
* Copyright (C) 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
*
* LysKOM is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* LysKOM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with LysKOM; see the file COPYING. If not, write to
* Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
* or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA.
*
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
#include
<stdio.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include
<signal.h>
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<fcntl.h>
#include
<errno.h>
#ifdef HAVE_STRING_H
# include <string.h>
#else
# ifdef HAVE_STRINGS_H
# include <strings.h>
# endif
#endif
#ifndef HAVE_STRCHR
# define strchr index
#endif
#include
<time.h>
#include
<unistd.h>
#ifndef HAVE_DIFFTIME
# include "tmp-difftime.h"
#endif
void
checkstatus
(
FILE
*
fp
)
{
char
lbuf
[
80
];
char
buf2
[
300
];
struct
stat
sbuf
;
if
(
fstat
(
fileno
(
fp
),
&
sbuf
)
<
0
)
{
perror
(
"updateLysKOM: stat failed"
);
exit
(
1
);
}
if
(
difftime
(
time
(
NULL
),
sbuf
.
st_mtime
)
<
3600
)
{
/* NOP */
}
else
if
(
difftime
(
time
(
NULL
),
sbuf
.
st_mtime
)
<
2
*
3600
)
{
/* Send mail to creator of file, the first line in the file. */
if
(
fgets
(
lbuf
,
80
,
fp
)
==
NULL
)
{
perror
(
"updateLysKOM: fgets failed"
);
exit
(
1
);
}
if
(
strchr
(
lbuf
,
'\n'
))
*
strchr
(
lbuf
,
'\n'
)
=
'\0'
;
sprintf
(
buf2
,
"echo 'Reminder: LysKOM is still not running.'|Mail %s"
,
lbuf
);
if
(
system
(
buf2
)
!=
0
)
{
perror
(
"updateLysKOM: system failed"
);
exit
(
1
);
}
}
else
{
if
(
system
(
"echo 'Note: LysKOM is down' | Mail ceder"
)
!=
0
)
{
perror
(
"updateLysKOM: system failed (2)"
);
exit
(
1
);
}
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
FILE
*
fp
;
if
(
getuid
()
==
0
||
geteuid
()
==
0
)
{
fprintf
(
stderr
,
"%s: this program should run as lyskom, not root
\n
"
,
argv
[
0
]);
exit
(
1
);
}
/* Parse command line arguments. */
for
(
i
=
1
;
i
<
argc
&&
argv
[
i
][
0
]
==
'-'
;
i
++
)
switch
(
argv
[
i
][
1
])
{
case
'V'
:
case
'v'
:
fprintf
(
stderr
,
"updateLysKOM $Revision: 1.1 $
\n
"
);
exit
(
0
);
default:
fprintf
(
stderr
,
"usage: %s [-V]
\n
"
,
argv
[
0
]);
}
fp
=
fopen
(
DEFAULT_PREFIX
"/etc/status"
,
"r"
);
if
(
fp
!=
NULL
)
{
checkstatus
(
fp
);
}
else
{
long
pid
;
fp
=
fopen
(
DEFAULT_PREFIX
"/etc/pid"
,
"r"
);
if
(
fp
==
NULL
)
{
fprintf
(
stderr
,
"%s: %s: "
,
argv
[
0
],
DEFAULT_PREFIX
"/etc/pid"
);
perror
(
""
);
exit
(
1
);
}
pid
=
0
;
fscanf
(
fp
,
"%lu"
,
&
pid
);
if
(
pid
==
0
||
pid
==
1
)
{
fprintf
(
stderr
,
"%s: got pid %ld.
\n
"
,
argv
[
0
],
pid
);
exit
(
1
);
}
if
(
kill
(
pid
,
SIGUSR1
)
!=
0
)
{
if
(
errno
!=
ESRCH
)
{
fprintf
(
stderr
,
"%s: kill(%ld, SIGUSR1) failed"
,
argv
[
0
],
pid
);
perror
(
""
);
exit
(
1
);
}
close
(
0
);
close
(
1
);
close
(
2
);
if
(
0
!=
open
(
"/dev/null"
,
O_RDONLY
)
||
1
!=
open
(
DEFAULT_PREFIX
"etc/stdout.log"
,
O_WRONLY
|
O_APPEND
|
O_CREAT
,
0666
)
||
2
!=
open
(
DEFAULT_PREFIX
"etc/stdout.log"
,
O_WRONLY
|
O_APPEND
|
O_CREAT
,
0666
))
{
fprintf
(
stderr
,
"%s: open"
,
argv
[
0
]);
perror
(
""
);
}
execl
(
DEFAULT_PREFIX
"/bin/lyskomd"
,
"lyskomd"
,
(
char
*
)
0
);
fprintf
(
stderr
,
"%s: execl() failed: "
,
argv
[
0
]);
perror
(
""
);
exit
(
1
);
}
}
exit
(
0
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment