MIDAS
Loading...
Searching...
No Matches
msetpriority.cxx
Go to the documentation of this file.
1
// msetpriority.cxx - set real time priority for event builder, etc
2
//
3
// this program has to be setuid-root: su - root; chown root; chmod u+s
4
//
5
// g++ -o bin/msetpriority -O2 -g -Wall progs/msetpriority.cxx
6
//
7
8
#include <stdio.h>
9
#include <unistd.h>
// getuid()
10
#include <sys/types.h>
// getuid()
11
#include <stdlib.h>
// exit()
12
#include <errno.h>
// errno
13
#include <string.h>
// strerror()
14
#include <sched.h>
// sched_setscheduler()
15
#include <sys/resource.h>
// setpriority()
16
17
18
int
main
(
int
argc
,
char
**
argv
)
19
{
20
int
status
;
21
22
// check if we are root
23
24
uid_t
uid
=
getuid
();
25
uid_t
euid
=
geteuid
();
26
27
//printf("uid %d, euid %d\n", uid, euid);
28
29
if
(
euid
!= 0) {
30
fprintf
(
stderr
,
"%s: must be setuid-root, please do: chown root, chmod u+s\n"
,
argv
[0]);
31
exit(1);
32
}
33
34
#if 1
35
struct
sched_param
sparam
;
36
sparam
.sched_priority = 50;
37
//status = sched_setscheduler(0, SCHED_RR, &sparam);
38
status
=
sched_setscheduler
(0,
SCHED_FIFO
, &
sparam
);
39
40
if
(
status
< 0) {
41
fprintf
(
stderr
,
"%s: sched_setscheduler() returned %d, errno %d (%s)\n"
,
argv
[0],
status
,
errno
,
strerror
(
errno
));
42
exit(1);
43
}
44
#endif
45
46
#if 0
47
status
=
setpriority
(
PRIO_PROCESS
, 0, -20);
48
49
if
(
status
< 0) {
50
fprintf
(
stderr
,
"%s: setpriority() returned %d, errno %d (%s)\n"
,
argv
[0],
status
,
errno
,
strerror
(
errno
));
51
exit(1);
52
}
53
#endif
54
55
// surrender root privileges
56
status
=
setuid
(
uid
);
57
58
if
(
status
< 0) {
59
fprintf
(
stderr
,
"%s: cannot surrender root priveleges, setuid(%d) returned %d, errno %d (%s)\n"
,
argv
[0],
uid
,
status
,
errno
,
strerror
(
errno
));
60
exit(1);
61
}
62
63
if
(
argc
< 2) {
64
fprintf
(
stderr
,
"Usage: %s program [arguments...]\n"
,
argv
[0]);
65
exit(1);
66
}
67
68
status
=
execvp
(
argv
[1], &
argv
[1]);
// does not return unless error.
69
70
fprintf
(
stderr
,
"%s: execvp(\"%s\") returned %d, errno %d (%s)\n"
,
argv
[0],
argv
[1],
status
,
errno
,
strerror
(
errno
));
71
exit(1);
72
}
73
74
// end
75
main
int main()
Definition
hwtest.cxx:23
status
DWORD status
Definition
odbhist.cxx:39
h1_book
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition
rmidas.h:24
progs
msetpriority.cxx
Generated on Sat May 3 2025 05:01:06 for MIDAS by
1.9.8