A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/run__with__lock_8c_source.html below:

NCBI C++ ToolKit: src/build-system/helpers/run_with_lock.c Source File

37 # define _GNU_SOURCE 1 46 #include <sys/select.h> 54 # define PATH_MAX 4096 58 # define W_EXITCODE(x, y) (((x) << 8) | (y)) 93

map_file = fopen(options->

map

,

"r"

);

94  if

(map_file ==

NULL

) {

95  if

(errno != ENOENT) {

97  "%s: Unable to open lock map %s: %s; leaving base as %s.\n"

,

102  while

(fgets(line,

sizeof

(line), map_file) !=

NULL

) {

104  if

(sscanf(line,

" %s %s"

,

key

,

value

) == 2

107

sprintf(new_base,

"make_%s"

,

value

);

108

fprintf(stderr,

"%s: Adjusting base from %s to %s per %s.\n"

,

110

options->

base

= new_base;

130  if

(

strcmp

((*argv)[1],

"-base"

) == 0 && *argc > 2) {

131

options->

base

= (*argv)[2];

134

}

else if

(

strcmp

((*argv)[1],

"-getter"

) == 0 && *argc > 2) {

135

options->

getter

= (*argv)[2];

138

}

else if

(

strcmp

((*argv)[1],

"-log"

) == 0 && *argc > 2) {

139

options->

logfile

= (*argv)[2];

142

}

else if

(

strcmp

((*argv)[1],

"-map"

) == 0 && *argc > 2) {

143

options->

map

= (*argv)[2];

146

}

else if

(

strcmp

((*argv)[1],

"-reviewer"

) == 0 && *argc > 2) {

150

}

else if

((*argv)[1][0] ==

'-'

) {

151

fprintf(stderr,

"%s: Unsupported option %s.\n"

,

154

}

else if

(

strcmp

((*argv)[1],

"!"

) == 0) {

163  if

(options->

base

==

NULL

&& *argc > 1) {

164  const char

* p = strrchr((*argv)[1],

'/'

);

166

options->

base

= p + 1;

168

options->

base

= (*argv)[1];

177  while

(

n

> 0 && (*p & 0xe0) == 0x20) {

181  return n

== 0 ?

NULL

: p;

192  if

(fwrite(

buffer

, 1,

n

, out1) <

n

) {

193

fprintf(stderr,

"%s: Error propagating process output: %s.\n"

,

202

fputc(

'\033'

, out2);

217  const char

* start = p;

218  const char

* src = p;

219  char

* dest = (

char

*) p;

221

&& (start = memchr(src,

'\033'

,

n

- (src - p))) !=

NULL 222

&& (start == p +

n

- 1 || start[1] ==

'['

)) {

223  if

(src > dest && start > src) {

224  memmove

(dest, src, start - src);

227  if

(start == p +

n

- 1) {

232  const char

* end =

s_FindEnd

(start + 2,

n

- 2 - (start - p));

246  if

(fwrite(p, 1,

n

, out2) <

n

) {

247

fprintf(stderr,

"%s: Error logging process output: %s.\n"

,

251  if

(

n

< 0 && errno != EAGAIN && errno != EWOULDBLOCK) {

253

fprintf(stderr,

"%s: Error reading from process: %s.\n"

,

273  const char

* term = getenv(

"TERM"

);

274  if

(term !=

NULL

&&

strcmp

(term,

"dumb"

) && isatty(fd_to_mimic)) {

278  if

((fds[0] = posix_openpt(O_RDONLY | O_NOCTTY)) < 0) {

279

fprintf(stderr,

"%s: Error allocating pty master for %s: %s.\n"

,

282

}

else if

(grantpt(fds[0]) < 0 || unlockpt(fds[0]) < 0

283

|| (name = ptsname(fds[0])) ==

NULL 284

|| (fds[1] = open(name, O_WRONLY)) < 0) {

285

fprintf(stderr,

"%s: Error opening pty slave for %s: %s.\n"

,

290  if

(tcgetattr(fds[1], &attr) < 0) {

292  "%s: Warning: unable to get attributes for %s: %s.\n"

,

295

attr.c_oflag |= ONLRET;

297

attr.c_oflag &= ~ONLCR;

300  if

(tcsetattr(fds[1], TCSADRAIN, &attr) < 0) {

302  "%s: Warning: unable to set attributes for %s: %s.\n"

,

308

fprintf(stderr,

"%s: Error creating pipe for %s: %s.n"

,

321  int

stdout_fds[2], stderr_fds[2];

330  if

(

s_OpenPipeOrPty

(STDERR_FILENO,

"stderr"

, stderr_fds, &stderr_state)

332  close

(stdout_fds[0]);

333  close

(stdout_fds[1]);

343

}

else if

(pid == 0) {

346  close

(stdout_fds[0]);

347  close

(stderr_fds[0]);

349

dup2(stderr_fds[1], STDERR_FILENO);

351  for

(

n

= 1;

n

<= NSIG; ++

n

) {

352  if

(

n

!= SIGKILL &&

n

!= SIGSTOP) {

356

execvp(args[0], (

char

*

const

*) args);

357

fprintf(stderr,

"%s: Unable to exec %s: %s.\n"

,

362  int

stdout_done = 0, stderr_done = 0;

363  close

(stdout_fds[1]);

364  close

(stderr_fds[1]);

365

fcntl(stdout_fds[0], F_SETFL,

366

fcntl(stdout_fds[0], F_GETFL) | O_NONBLOCK);

367

fcntl(stderr_fds[0], F_SETFL,

368

fcntl(stderr_fds[0], F_GETFL) | O_NONBLOCK);

369  while

( !stdout_done || !stderr_done ) {

371  unsigned int

nfds = 0;

374  if

( !stderr_done ) {

375

FD_SET(stderr_fds[0], &rfds);

376

FD_SET(stderr_fds[0], &efds);

377

nfds = stderr_fds[0] + 1;

379  if

( !stdout_done ) {

380

FD_SET(stdout_fds[0], &rfds);

381

FD_SET(stdout_fds[0], &efds);

382  if

(stdout_fds[0] >= nfds) {

383

nfds = stdout_fds[0] + 1;

386  if

(select(nfds, &rfds,

NULL

, &efds,

NULL

) < 0

387

&& errno != EINTR && errno != EAGAIN) {

389  "%s: Error checking for output to log: %s.\n"

,

393  if

(FD_ISSET(stdout_fds[0], &rfds)

394

|| FD_ISSET(stdout_fds[0], &efds)) {

395

stdout_done =

s_Tee

(stdout_fds[0], stdout,

log

,

398  if

(FD_ISSET(stderr_fds[0], &rfds)

399

|| FD_ISSET(stderr_fds[0], &efds)) {

400

stderr_done =

s_Tee

(stderr_fds[0], stderr,

log

,

404

&& waitpid(pid, &status, WNOHANG) != 0) {

418

waitpid(pid, &status, 0);

423  close

(stdout_fds[0]);

424  close

(stderr_fds[0]);

444

fprintf(stderr,

"%s: Caught signal %d\n"

,

s_AppName

,

n

);

461 int main

(

int

argc,

const char

*

const

* argv)

464  char

pid_str[

sizeof

(pid_t) * 3 + 1], new_log[

PATH_MAX

];

465  const char

* getter_args[] = {

"get_lock"

,

"BASE"

, pid_str,

NULL

};

477

getter_args[0] = options.

getter

;

479

getter_args[1] = options.

base

;

480

sprintf(pid_str,

"%ld"

, (

long

)getpid());

482  for

(

n

= 1;

n

<= NSIG; ++

n

) {

485  case

SIGQUIT:

case

SIGILL:

case

SIGABRT:

case

SIGFPE:

case

SIGSEGV:

486  case

SIGBUS:

case

SIGSYS:

case

SIGTRAP:

case

SIGXCPU:

case

SIGXFSZ:

490  case

SIGKILL:

case

SIGSTOP:

492  case

SIGTSTP:

case

SIGTTIN:

case

SIGTTOU:

494  case

SIGCHLD:

case

SIGCONT:

case

SIGURG:

case

SIGWINCH:

507

sprintf(new_log,

"%s.new"

, options.

logfile

);

508  log

= fopen(new_log,

"w"

);

510

fprintf(stderr,

"%s: Couldn't open log file %s: %s.\n"

,

523  if

(access(options.

logfile

, F_OK) != 0) {

526  const char

* reviewer_args[] = { options.

reviewer

, new_log,

NULL

};

527  if

(

s_Run

(reviewer_args,

NULL

) != 0) {

532  if

(rename(new_log, options.

logfile

) < 0) {

533

fprintf(stderr,

"%s: Unable to rename log file %s: %s.\n"

,

544

}

else if

(WIFSIGNALED(status)) {

545

status = WTERMSIG(status) | 0x80;

547

status = WEXITSTATUS(status);

static void cleanup(void)

static const char label[]

const struct ncbi::grid::netcache::search::fields::KEY key

const GenericPointer< typename T::ValueType > T2 value

int strncmp(const char *str1, const char *str2, size_t count)

int strcmp(const char *str1, const char *str2)

std::istream & in(std::istream &in_, double &x_)

int main(int argc, const char *const *argv)

static int s_FinishingInBackground

static const char * s_FindEnd(const char *p, size_t n)

static void s_CleanUp(void)

static void s_ParseOptions(SOptions *options, int *argc, const char *const **argv)

static const char * s_AppName

static int s_OpenPipeOrPty(int fd_to_mimic, const char *label, int fds[2], EFilterState *state)

static int s_Run(const char *const *args, FILE *log)

static int s_CaughtSignal

static void s_OnSignal(int n)

static char s_LockName[4096]

static sig_t s_OrigHandlers[NSIG+1]

static void s_OnSIGCHLD(int n)

static void s_ApplyMap(SOptions *options)

static int s_MainChildDone

static int s_Tee(int in, FILE *out1, FILE *out2, EFilterState *state)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4