/* This stays around for as long as the initial process in the app does
* and when that exits it exits, propagating the exit status. We do this
* by having pid 1 in the sandbox detect this exit and tell the monitor
* the exit status via a eventfd. We also track the exit of the sandbox
* pid 1 via a signalfd for SIGCHLD, and exit with an error in this case.
* This is to catch e.g. problems during setup. */
static void
monitor_child (int event_fd)
{
int res;
uint64_t val;
ssize_t s;
int signal_fd;
sigset_t mask;
struct pollfd fds[2];
int num_fds;
struct signalfd_siginfo fdsi;
int dont_close[] = { event_fd, -1 };
/* Close all extra fds in the monitoring process.
Any passed in fds have been passed on to the child anyway. */
fdwalk (proc_fd, close_extra_fds, dont_close);
sigemptyset (&mask);
sigaddset (&mask, SIGCHLD);
signal_fd = signalfd (-1, &mask, SFD_CLOEXEC | SFD_NONBLOCK);
if (signal_fd == -1)
die_with_error ("Can't create signalfd");
num_fds = 1;
fds[0].fd = signal_fd;
fds[0].events = POLLIN;
if (event_fd != -1)
{
fds[1].fd = event_fd;
fds[1].events = POLLIN;
num_fds++;
}
while (1)
{
fds[0].revents = fds[1].revents = 0;
res = poll (fds, num_fds, -1);
if (res == -1 && errno != EINTR)
die_with_error ("poll");
/* Always read from the eventfd first, if pid 2 died then pid 1 often
* dies too, and we could race, reporting that first and we'd lose
* the real exit status. */
if (event_fd != -1)
{
s = read (event_fd, &val, 8);
if (s == -1 && errno != EINTR && errno != EAGAIN)
die_with_error ("read eventfd");
else if (s == 8)
exit ((int)val - 1);
}
s = read (signal_fd, &fdsi, sizeof (struct signalfd_siginfo));
if (s == -1 && errno != EINTR && errno != EAGAIN)
die_with_error ("read signalfd");
else if (s == sizeof(struct signalfd_siginfo))
{
if (fdsi.ssi_signo != SIGCHLD)
die ("Read unexpected signal\n");
exit (fdsi.ssi_status);
}
}
}
static unsigned char *bktr_device_init(struct video_dev *viddev, int width, int height,
unsigned input, unsigned norm, unsigned long freq)
{
int dev_bktr = viddev->fd_device;
struct sigaction act, old;
//int dev_tunner = viddev->fd_tuner;
/* to ensure that all device will be support the capture mode
_TODO_ : Autodected the best capture mode .
*/
int dummy = 1;
// int pixelformat = BSD_VIDFMT_I420;
void *map;
/* If we have choose the tuner is needed to setup the frequency. */
if ((viddev->tuner_device != NULL) && (input == BKTR_IN_TV)) {
if (!freq) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Not valid Frequency [%lu] for "
"Source input [%i]", freq, input);
return NULL;
} else if (bktr_set_freq(viddev, freq) == -1) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Frequency [%lu] Source input [%i]",
freq, input);
return NULL;
}
}
/* FIXME if we set as input tuner , we need to set option for tuner not for bktr */
if ((dummy = bktr_set_input_device(viddev, input)) == -1) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set input [%d]", input);
return NULL;
}
viddev->input = dummy;
if ((dummy = bktr_set_input_format(viddev, norm)) == -1) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set input format [%d]",
norm);
return NULL;
}
viddev->norm = dummy;
if (bktr_set_geometry(viddev, width, height) == -1) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set geometry [%d]x[%d]",
width, height);
return NULL;
}
if (freq) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Frequency set (no implemented yet");
}
/*
* Set capture mode and capture buffers
* That is the buffer size for capture images ,
* so is dependent of color space of input format / FIXME
*/
viddev->v4l_bufsize = (((width * height * 3 / 2)) * sizeof(unsigned char));
viddev->v4l_fmt = VIDEO_PALETTE_YUV420P;
map = mmap((caddr_t)0, viddev->v4l_bufsize, PROT_READ|PROT_WRITE, MAP_SHARED,
dev_bktr, (off_t)0);
if (map == MAP_FAILED) {
MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: mmap failed");
return NULL;
}
/* FIXME double buffer */
if (0) {
viddev->v4l_maxbuffer = 2;
viddev->v4l_buffers[0] = map;
viddev->v4l_buffers[1] = (unsigned char *)map + 0; /* 0 is not valid just a test */
//viddev->v4l_buffers[1] = map+vid_buf.offsets[1];
} else {
viddev->v4l_buffers[0] = map;
viddev->v4l_maxbuffer = 1;
}
viddev->v4l_curbuffer = 0;
/* Clear the buffer */
if (ioctl(dev_bktr, BT848SCBUF, &dummy) < 0) {
MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SCBUF");
return NULL;
}
/* Signal handler to know when data is ready to be read() */
memset(&act, 0, sizeof(act));
sigemptyset(&act.sa_mask);
act.sa_handler = catchsignal;
sigaction(SIGUSR2, &act, &old);
dummy = SIGUSR2;
//viddev->capture_method = METEOR_CAP_CONTINOUS;
//viddev->capture_method = METEOR_CAP_SINGLE;
//.........这里部分代码省略.........
开发者ID:jogu,项目名称:motion,代码行数:101,代码来源:video_bktr.c
示例9: gfx_ctx_drm_egl_set_video_mode
static bool gfx_ctx_drm_egl_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
{
static const EGLint egl_attribs_gl[] = {
DRM_EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE,
};
static const EGLint egl_attribs_gles[] = {
DRM_EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE,
};
#ifdef EGL_KHR_create_context
static const EGLint egl_attribs_gles3[] = {
DRM_EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
EGL_NONE,
};
#endif
static const EGLint egl_attribs_vg[] = {
DRM_EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE,
};
const EGLint *attrib_ptr;
EGLint major, minor, n, egl_attribs[16], *attr;
float refresh_mod;
int i, ret = 0;
struct sigaction sa = {{0}};
struct drm_fb *fb = NULL;
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)
driver->video_context_data;
if (!drm)
return false;
sa.sa_handler = sighandler;
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
switch (g_api)
{
case GFX_CTX_OPENGL_API:
attrib_ptr = egl_attribs_gl;
break;
case GFX_CTX_OPENGL_ES_API:
#ifdef EGL_KHR_create_context
if (g_major >= 3)
attrib_ptr = egl_attribs_gles3;
else
#endif
attrib_ptr = egl_attribs_gles;
break;
case GFX_CTX_OPENVG_API:
attrib_ptr = egl_attribs_vg;
break;
default:
attrib_ptr = NULL;
}
/* If we use black frame insertion,
* we fake a 60 Hz monitor for 120 Hz one, etc, so try to match that. */
refresh_mod = settings->video.black_frame_insertion ? 0.5f : 1.0f;
/* Find desired video mode, and use that.
* If not fullscreen, we get desired windowed size,
* which is not appropriate. */
if ((width == 0 && height == 0) || !fullscreen)
drm->g_drm_mode = &drm->g_connector->modes[0];
else
{
/* Try to match settings->video.refresh_rate as closely as possible.
* Lower resolutions tend to have multiple supported
* refresh rates as well.
*/
float minimum_fps_diff = 0.0f;
/* Find best match. */
for (i = 0; i < drm->g_connector->count_modes; i++)
{
float diff;
if (width != drm->g_connector->modes[i].hdisplay ||
height != drm->g_connector->modes[i].vdisplay)
continue;
diff = fabsf(refresh_mod * drm->g_connector->modes[i].vrefresh
- settings->video.refresh_rate);
if (!drm->g_drm_mode || diff < minimum_fps_diff)
{
//.........这里部分代码省略.........
static void run_monitored(char *executable, int argc, char **argv) {
int pid;
const char *t = getenv("KLEE_REPLAY_TIMEOUT");
if (!t)
t = "10000000";
monitored_timeout = atoi(t);
if (monitored_timeout==0) {
fprintf(stderr, "ERROR: invalid timeout (%s)\n", t);
_exit(1);
}
/* Kill monitored process(es) on SIGINT and SIGTERM */
signal(SIGINT, int_handler);
signal(SIGTERM, int_handler);
signal(SIGALRM, timeout_handler);
pid = fork();
if (pid < 0) {
perror("fork");
_exit(66);
} else if (pid == 0) {
/* This process actually executes the target program.
*
* Create a new process group for pid, and the process tree it may spawn. We
* do this, because later on we might want to kill pid _and_ all processes
* spawned by it and its descendants.
*/
setpgrp();
if (!rootdir) {
execv(executable, argv);
perror("execv");
_exit(66);
}
fprintf(stderr, "rootdir: %s\n", rootdir);
const char *msg;
if ((msg = "chdir", chdir(rootdir) == 0) &&
(msg = "chroot", chroot(rootdir) == 0)) {
msg = "execv";
executable = strip_root_dir(executable, rootdir);
argv[0] = strip_root_dir(argv[0], rootdir);
execv(executable, argv);
}
perror(msg);
_exit(66);
} else {
/* Parent process which monitors the child. */
int res, status;
time_t start = time(0);
sigset_t masked;
sigemptyset(&masked);
sigaddset(&masked, SIGALRM);
monitored_pid = pid;
alarm(monitored_timeout);
do {
res = waitpid(pid, &status, 0);
} while (res < 0 && errno == EINTR);
if (res < 0) {
perror("waitpid");
_exit(66);
}
/* Just in case, kill the process group of pid. Since we called setpgrp()
for pid, this will not kill us, or any of our ancestors */
kill(-pid, SIGKILL);
process_status(status, time(0) - start, 0);
}
}
开发者ID:ahorn,项目名称:klee,代码行数:73,代码来源:klee-replay.c
示例14: main
int
main(int argc, char *argv[])
{
struct sigaction sa;
int fd, events, fnum;
const int NOTIFY_SIG = SIGRTMIN;
char *p;
if (argc < 2 || strcmp(argv[1], "--help") == 0)
usageError(argv[0], NULL);
/* Establish handler for notification signal */
sa.sa_sigaction = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO; /* So handler gets siginfo_t arg. */
if (sigaction(NOTIFY_SIG, &sa, NULL) == -1)
errExit("sigaction");
for (fnum = 1; fnum < argc; fnum++) {
p = strchr(argv[fnum], ':'); /* Look for optional ':' */
if (p == NULL) { /* Default is all events + multishot */
events = DN_ACCESS | DN_ATTRIB | DN_CREATE | DN_DELETE |
DN_MODIFY | DN_RENAME | DN_MULTISHOT;
} else { /* ':' present, parse event chars */
*p = '\0'; /* Terminates directory component */
events = 0;
for (p++; *p != '\0'; p++) {
switch (*p) {
case 'a': events |= DN_ACCESS; break;
case 'A': events |= DN_ATTRIB; break;
case 'c': events |= DN_CREATE; break;
case 'd': events |= DN_DELETE; break;
case 'm': events |= DN_MODIFY; break;
case 'r': events |= DN_RENAME; break;
case 'M': events |= DN_MULTISHOT; break;
default: usageError(argv[0], "Bad event character\n");
}
}
}
/* Obtain a file descriptor for the directory to be monitored */
fd = open(argv[fnum], O_RDONLY);
if (fd == -1)
errExit("open");
printf("opened '%s' as file descriptor %d\n", argv[fnum], fd);
/* Use alternate signal instead of SIGIO for dnotify events */
if (fcntl(fd, F_SETSIG, NOTIFY_SIG) == -1)
errExit("fcntl - F_SETSIG");
/* Enable directory change notifications */
if (fcntl(fd, F_NOTIFY, events) == -1)
errExit("fcntl-F_NOTIFY");
printf("events: %o\n", (unsigned int) events);
}
for (;;)
pause(); /* Wait for events */
}
int
main(int argc, char **argv)
{ /*Main program */
int cellNum; /*Cell entry number */
int rc; /*Return value from U_CellGetLocalTokens */
time_t current_time; /*Current time of day */
time_t tokenExpireTime; /*When token expires */
char *expireString; /*Char string of expiration time */
char UserName[MAXKTCNAMELEN * 2 + 2]; /*Printable user name */
char *cellName;
struct ktc_principal clientName; /* service name for ticket */
struct ktc_token token; /* the token we're printing */
struct ktc_setTokenData *tokenSet;
#ifdef AFS_AIX32_ENV
/*
* The following signal action for AIX is necessary so that in case of a
* crash (i.e. core is generated) we can include the user's data section
* in the core dump. Unfortunately, by default, only a partial core is
* generated which, in many cases, isn't too useful.
*/
struct sigaction nsa;
sigemptyset(&nsa.sa_mask);
nsa.sa_handler = SIG_DFL;
nsa.sa_flags = SA_FULLDUMP;
sigaction(SIGSEGV, &nsa, NULL);
#endif
/* has no args ... support for help flag */
if (argc > 1) {
/* syntax from AFS Com Ref Man p9-39 */
printf("Usage: tokens [-help]\n");
fflush(stdout);
exit(0);
}
printf("\nTokens held by the Cache Manager:\n\n");
cellNum = 0;
current_time = time(0);
while (1) {
rc = ktc_ListTokensEx(cellNum, &cellNum, &cellName);
if (rc) {
/* only error is now end of list */
printf(" --End of list--\n");
break;
} else {
/* get the ticket info itself */
rc = ktc_GetTokenEx(cellName, &tokenSet);
if (rc) {
printf
("tokens: failed to get token info for cell %s (code %d)\n",
cellName, rc);
continue;
}
rc = token_extractRxkad(tokenSet, &token, NULL, &clientName);
if (rc == 0) {
tokenExpireTime = token.endTime;
strcpy(UserName, clientName.name);
if (clientName.instance[0] != 0) {
strcat(UserName, ".");
strcat(UserName, clientName.instance);
}
if (UserName[0] == 0)
printf("rxkad Tokens");
else if (strncmp(UserName, "AFS ID", 6) == 0) {
printf("User's (%s) rxkad tokens", UserName);
} else if (strncmp(UserName, "Unix UID", 8) == 0) {
printf("RxkadTokens");
} else
printf("User %s's rxkad tokens", UserName);
printf(" for %s ", cellName);
if (tokenExpireTime <= current_time)
printf("[>> Expired <<]\n");
else {
expireString = ctime(&tokenExpireTime);
expireString += 4; /*Move past the day of week */
expireString[12] = '\0';
printf("[Expires %s]\n", expireString);
}
}
token_FreeSet(&tokenSet);
}
}
exit(0);
} /*Main program */
开发者ID:bagdxk,项目名称:openafs,代码行数:88,代码来源:tokens.c
示例16: solarisSyncInit
CVMBool
solarisSyncInit(void)
{
struct sigaction sa;
sa.sa_handler = sigfunc1; /* interrupt wait */
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
/*
* but we allow interrupt-wait to be interrupted by a
* set-owner request
*/
sigaction(SIGUSR2, &sa, NULL);
sigemptyset(&CVMtargetGlobals->sigusr2Mask);
sigaddset(&CVMtargetGlobals->sigusr2Mask, SIGUSR2);
#if defined(CVM_JVMPI) || defined(CVM_JVMTI)
sa.sa_handler = sigquitHandler;
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
/*
* mask SIGQUIT, so set-owner cannot be interrupted by an
* interrupt-wait request
*/
sigaddset(&sa.sa_mask, SIGQUIT);
sigaction(SIGQUIT, &sa, NULL);
#endif
#ifdef CVM_ADV_MUTEX_SET_OWNER
/* Sanity check to make sure raw copy of locked mutex is safe */
{
POSIXMutex test1, test2;
memset(&test1, 0, sizeof test1);
memset(&test2, 0, sizeof test2);
if (!POSIXmutexInit(&test1)) {
return CVM_FALSE;
} else {
CVMBool ok;
if (!POSIXmutexInit(&test2)) {
POSIXmutexDestroy(&test1);
return CVM_FALSE;
}
ok = POSIXmutexTryLock(&test2);
if (!ok) {
fprintf(stderr, "trylock failed\n");
POSIXmutexDestroy(&test1);
POSIXmutexDestroy(&test2);
return CVM_FALSE;
}
ok = POSIXmutexTryLock(&test1);
if (!ok) {
fprintf(stderr, "trylock failed\n");
POSIXmutexDestroy(&test1);
POSIXmutexUnlock(&test2);
POSIXmutexDestroy(&test2);
return CVM_FALSE;
}
ok = (memcmp(&test1, &test2, sizeof test1) == 0);
POSIXmutexUnlock(&test1);
POSIXmutexDestroy(&test1);
POSIXmutexUnlock(&test2);
POSIXmutexDestroy(&test2);
if (!ok) {
fprintf(stderr, "locked mutexes not identical\n");
return CVM_FALSE;
}
}
}
#endif
#ifdef CVM_JIT
return solarisJITSyncInitArch();
#else
return CVM_TRUE;
#endif
}
请发表评论