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
20077630
Commit
20077630
authored
Apr 09, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ccanlint: always catch timeouts, and force kill valgrind etc.
parent
30465202
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
+12
-7
tools/tools.c
tools/tools.c
+12
-7
No files found.
tools/tools.c
View file @
20077630
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#include <stdarg.h>
#include <stdarg.h>
#include <errno.h>
#include <errno.h>
#include <err.h>
#include <err.h>
#include <unistd.h>
#include "tools.h"
#include "tools.h"
static
char
*
tmpdir
=
NULL
;
static
char
*
tmpdir
=
NULL
;
...
@@ -57,6 +58,11 @@ char *talloc_getcwd(const void *ctx)
...
@@ -57,6 +58,11 @@ char *talloc_getcwd(const void *ctx)
return
cwd
;
return
cwd
;
}
}
static
void
killme
(
int
sig
)
{
kill
(
-
getpid
(),
SIGKILL
);
}
static
char
*
run_with_timeout
(
const
void
*
ctx
,
static
char
*
run_with_timeout
(
const
void
*
ctx
,
const
char
*
cmd
,
const
char
*
cmd
,
bool
*
ok
,
bool
*
ok
,
...
@@ -73,6 +79,7 @@ static char *run_with_timeout(const void *ctx,
...
@@ -73,6 +79,7 @@ static char *run_with_timeout(const void *ctx,
return
talloc_asprintf
(
ctx
,
"Failed to create pipe: %s"
,
return
talloc_asprintf
(
ctx
,
"Failed to create pipe: %s"
,
strerror
(
errno
));
strerror
(
errno
));
gettimeofday
(
&
start
,
NULL
);
pid
=
fork
();
pid
=
fork
();
if
(
pid
==
-
1
)
{
if
(
pid
==
-
1
)
{
close_noerr
(
p
[
0
]);
close_noerr
(
p
[
0
]);
...
@@ -92,6 +99,8 @@ static char *run_with_timeout(const void *ctx,
...
@@ -92,6 +99,8 @@ static char *run_with_timeout(const void *ctx,
||
open
(
"/dev/null"
,
O_RDONLY
)
!=
STDIN_FILENO
)
||
open
(
"/dev/null"
,
O_RDONLY
)
!=
STDIN_FILENO
)
exit
(
128
);
exit
(
128
);
setpgid
(
0
,
0
);
signal
(
SIGALRM
,
killme
);
itim
.
it_interval
.
tv_sec
=
itim
.
it_interval
.
tv_usec
=
0
;
itim
.
it_interval
.
tv_sec
=
itim
.
it_interval
.
tv_usec
=
0
;
itim
.
it_value
.
tv_sec
=
*
timeout_ms
/
1000
;
itim
.
it_value
.
tv_sec
=
*
timeout_ms
/
1000
;
itim
.
it_value
.
tv_usec
=
(
*
timeout_ms
%
1000
)
*
1000
;
itim
.
it_value
.
tv_usec
=
(
*
timeout_ms
%
1000
)
*
1000
;
...
@@ -105,17 +114,12 @@ static char *run_with_timeout(const void *ctx,
...
@@ -105,17 +114,12 @@ static char *run_with_timeout(const void *ctx,
}
}
close
(
p
[
1
]);
close
(
p
[
1
]);
gettimeofday
(
&
start
,
NULL
);
ret
=
grab_fd
(
ctx
,
p
[
0
],
NULL
);
ret
=
grab_fd
(
ctx
,
p
[
0
],
NULL
);
/* This shouldn't fail... */
/* This shouldn't fail... */
if
(
waitpid
(
pid
,
&
status
,
0
)
!=
pid
)
if
(
waitpid
(
pid
,
&
status
,
0
)
!=
pid
)
err
(
1
,
"Failed to wait for child"
);
err
(
1
,
"Failed to wait for child"
);
gettimeofday
(
&
end
,
NULL
);
gettimeofday
(
&
end
,
NULL
);
if
(
WIFSIGNALED
(
status
))
{
*
timeout_ms
=
0
;
return
ret
;
}
if
(
end
.
tv_usec
<
start
.
tv_usec
)
{
if
(
end
.
tv_usec
<
start
.
tv_usec
)
{
end
.
tv_usec
+=
1000000
;
end
.
tv_usec
+=
1000000
;
end
.
tv_sec
--
;
end
.
tv_sec
--
;
...
@@ -127,7 +131,7 @@ static char *run_with_timeout(const void *ctx,
...
@@ -127,7 +131,7 @@ static char *run_with_timeout(const void *ctx,
else
else
*
timeout_ms
-=
ms
;
*
timeout_ms
-=
ms
;
*
ok
=
(
WEXITSTATUS
(
status
)
==
0
);
*
ok
=
(
W
IFEXITED
(
status
)
&&
W
EXITSTATUS
(
status
)
==
0
);
return
ret
;
return
ret
;
}
}
...
@@ -155,7 +159,8 @@ char *run_command(const void *ctx, unsigned int *time_ms, const char *fmt, ...)
...
@@ -155,7 +159,8 @@ char *run_command(const void *ctx, unsigned int *time_ms, const char *fmt, ...)
if
(
!
contents
)
if
(
!
contents
)
err
(
1
,
"Problem running child"
);
err
(
1
,
"Problem running child"
);
if
(
*
time_ms
==
0
)
if
(
*
time_ms
==
0
)
talloc_asprintf_append
(
contents
,
"
\n
== TIMED OUT ==
\n
"
);
contents
=
talloc_asprintf_append
(
contents
,
"
\n
== TIMED OUT ==
\n
"
);
return
contents
;
return
contents
;
}
}
...
...
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