Changeset 2333
- Timestamp:
- Aug 5, 2011, 3:23:31 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanoscale/server.c
r2246 r2333 76 76 77 77 78 #include <syslog.h> 79 #include <stdarg.h> 80 81 #define ERROR(...) LogMessage(LOG_ERR, __FILE__, __LINE__, __VA_ARGS__) 82 #ifdef WANT_TRACE 83 #define TRACE(...) LogMessage(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__) 84 #else 85 #define TRACE(...) 86 #endif 87 #define WARN(...) LogMessage(LOG_WARNING, __FILE__, __LINE__, __VA_ARGS__) 88 #define INFO(...) LogMessage(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__) 89 90 void 91 LogMessage(int priority, const char *path, int lineNum, const char* fmt, ...) 92 { 93 #define MSG_LEN (2047) 94 char message[MSG_LEN+1]; 95 const char *s; 96 int length; 97 va_list lst; 98 99 va_start(lst, fmt); 100 s = strrchr(path, '/'); 101 if (s == NULL) { 102 s = path; 103 } else { 104 s++; 105 } 106 length = snprintf(message, MSG_LEN, "line %d of \"%s\": ", lineNum, s); 107 length += vsnprintf(message + length, MSG_LEN - length, fmt, lst); 108 message[MSG_LEN] = '\0'; 109 syslog(priority, message, length); 110 } 111 78 112 static void 79 113 close_child(int pipe_fd) … … 125 159 help(const char *argv0) 126 160 { 127 fprintf(stderr, 128 "Syntax: %s [-d] -b <broadcast port> -l <listen port> -s <subnet> -c 'command'\n", 161 INFO("Syntax: %s [-d] -b <broadcast port> -l <listen port> -s <subnet> -c 'command'\n", 129 162 argv0); 130 163 exit(1); … … 183 216 maxCards = strtoul(optarg, 0, 0); 184 217 if ((maxCards < 1) || (maxCards > 10)) { 185 fprintf(stderr,"bad number of max videocards specified\n");218 ERROR("bad number of max videocards specified\n"); 186 219 return 1; 187 220 } … … 197 230 198 231 if (listen_port[nservices] == -1) { 199 fprintf(stderr,"Must specify -l port before each -c command.\n");232 ERROR("Must specify -l port before each -c command.\n"); 200 233 return 1; 201 234 } … … 210 243 send_addr.sin_addr.s_addr = htonl(inet_network(optarg)); 211 244 if (send_addr.sin_addr.s_addr == -1) { 212 fprintf(stderr,"Invalid subnet broadcast address");245 ERROR("Invalid subnet broadcast address"); 213 246 return 1; 214 247 } 215 248 break; 216 249 default: 217 fprintf(stderr,"Don't know what option '%c'.\n", c);250 ERROR("Don't know what option '%c'.\n", c); 218 251 return 1; 219 252 } … … 224 257 int i; 225 258 for (i = 0; i < argc; i++) { 226 fprintf(stderr,"argv[%d]=(%s)\n", i, argv[i]);259 INFO("argv[%d]=(%s)\n", i, argv[i]); 227 260 } 228 261 help(argv[0]); … … 395 428 } 396 429 if (status != 8) { 397 fprintf(stderr,"Bogus message from %s\n", 398 inet_ntoa(peer_addr.sin_addr)); 430 ERROR("Bogus message from %s\n", inet_ntoa(peer_addr.sin_addr)); 399 431 continue; 400 432 } … … 453 485 status = read(i, &msg, 4); 454 486 if (status != 4) { 455 fprintf(stderr,"Bad status on read (%d).", status);487 ERROR("Bad status on read (%d).", status); 456 488 FD_CLR(i, &saved_rfds); 457 489 clear_service_fd(i); … … 465 497 memory_in_use += newmemory; 466 498 load += 2*INITIAL_LOAD; 467 printf("Accepted new job with memory %d\n", newmemory);499 INFO("Accepted new job with memory %d\n", newmemory); 468 500 //printf("My load is now %f\n", load); 469 501 … … 471 503 msg = 0; 472 504 if (write(i, &msg, 4) != 4) { 473 fprintf(stderr,"short write for hostname\n");505 ERROR("short write for hostname\n"); 474 506 } 475 507 … … 521 553 displayVar[11] = dispNum + '0'; 522 554 } 523 execvp(command_argv[n][0], command_argv[n]); 555 if (execvp(command_argv[n][0], command_argv[n]) < 1) { 556 extern int errno; 557 558 ERROR("can't execute \"%s\": %s\n", 559 command_argv[n][0], strerror(errno)); 560 } 524 561 } 525 562 _exit(errno);
Note: See TracChangeset
for help on using the changeset viewer.