Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
e22e4bd1
Commit
e22e4bd1
authored
Apr 15, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Daemonize test.
parent
75a2f5a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
ccan/daemonize/test/run.c
ccan/daemonize/test/run.c
+65
-0
No files found.
ccan/daemonize/test/run.c
0 → 100644
View file @
e22e4bd1
#include <ccan/daemonize/daemonize.h>
#include <ccan/daemonize/daemonize.c>
#include <ccan/tap/tap.h>
#include <stdlib.h>
#include <unistd.h>
#include <err.h>
#include <errno.h>
struct
child_data
{
pid_t
pid
;
pid_t
ppid
;
bool
in_root_dir
;
int
read_from_stdin
,
write_to_stdout
,
write_to_stderr
;
};
int
main
(
int
argc
,
char
*
argv
[])
{
int
fds
[
2
];
struct
child_data
daemonized
;
pid_t
pid
;
plan_tests
(
6
);
if
(
pipe
(
fds
)
!=
0
)
err
(
1
,
"Failed pipe"
);
/* Since daemonize forks and parent exits, we need to fork
* that parent. */
pid
=
fork
();
if
(
pid
==
-
1
)
err
(
1
,
"Failed fork"
);
if
(
pid
==
0
)
{
char
buffer
[
2
];
pid
=
getpid
();
daemonize
();
daemonized
.
pid
=
getpid
();
daemonized
.
in_root_dir
=
(
getcwd
(
buffer
,
2
)
!=
NULL
);
daemonized
.
read_from_stdin
=
read
(
STDIN_FILENO
,
buffer
,
1
)
==
-
1
?
errno
:
0
;
daemonized
.
write_to_stdout
=
write
(
STDOUT_FILENO
,
buffer
,
1
)
==
-
1
?
errno
:
0
;
daemonized
.
write_to_stderr
=
write
(
STDERR_FILENO
,
buffer
,
1
)
==
-
1
?
errno
:
0
;
/* Make sure parent exits. */
while
(
getppid
()
==
pid
)
sleep
(
1
);
daemonized
.
ppid
=
getppid
();
write
(
fds
[
1
],
&
daemonized
,
sizeof
(
daemonized
));
exit
(
0
);
}
if
(
read
(
fds
[
0
],
&
daemonized
,
sizeof
(
daemonized
))
!=
sizeof
(
daemonized
))
err
(
1
,
"Failed read"
);
ok1
(
daemonized
.
pid
!=
pid
);
ok1
(
daemonized
.
ppid
==
1
);
ok1
(
daemonized
.
in_root_dir
);
ok1
(
daemonized
.
read_from_stdin
==
EBADF
);
ok1
(
daemonized
.
write_to_stdout
==
EBADF
);
ok1
(
daemonized
.
write_to_stderr
==
EBADF
);
return
exit_status
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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