Changeset 2488 for neercs/trunk/src/main.c
- Timestamp:
- 06/25/08 00:33:40 (5 years ago)
- File:
-
- 1 edited
-
neercs/trunk/src/main.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/main.c
r2487 r2488 68 68 printf("Example : %s zsh top \n\n", argv[0]); 69 69 printf("Options :\n"); 70 printf("\t--config\t\t-c <file>\t\tuse given config file\n"); 71 printf("\t--pid\t\t-P <pid>\t\tattach <pid>\n"); 72 printf("\t\t\t-R\t\t\tre-attach another neercs\n"); 70 printf("\t--config\t-c <file>\t\tuse given config file\n"); 71 printf("\t--pid\t\t-P <pid>\t\tgrab <pid>\n"); 72 printf("\t\t\t-r [session]\t\treattach to a detached neercs\n"); 73 printf("\t\t\t-R [session]\t\treattach if possible, otherwise start a new session\n"); 74 printf("\t\t\t-S <name>\t\tname this session <name> instead of <pid>\n"); 73 75 printf("\t--version\t-v \t\t\tdisplay version and exit\n"); 74 76 printf("\t--help\t\t-h \t\t\tthis help\n"); … … 82 84 struct recurrent_list *recurrent_list = NULL; 83 85 struct passwd *user_info; 84 char *default_shell = NULL, *user_path = NULL ;86 char *default_shell = NULL, *user_path = NULL, *session_name = NULL; 85 87 int i, w, h, args, s=0; 86 88 int eof = 0, refresh = 1, command = 0; … … 88 90 int lock_offset = 0; 89 91 int mainret = 0; 90 int attach = 0 ;92 int attach = 0, forceattach = 0; 91 93 int *to_grab = NULL; 92 94 int nb_to_grab = 0; … … 142 144 screen_list->socket_dir = NULL; 143 145 screen_list->socket_path = NULL; 146 screen_list->session_name = NULL; 144 147 memset(screen_list->lockmsg, 0, 1024); 145 148 memset(screen_list->lockpass, 0, 1024); … … 168 171 }; 169 172 #if defined USE_GRAB 170 int c = mygetopt(argc, argv, "c: RP:hv", long_options, &option_index);173 int c = mygetopt(argc, argv, "c:S:R::r::P:hv", long_options, &option_index); 171 174 #else 172 int c = mygetopt(argc, argv, "c: Rhv", long_options, &option_index);175 int c = mygetopt(argc, argv, "c:S:R::r::hv", long_options, &option_index); 173 176 #endif 174 177 if(c == -1) … … 181 184 free(user_path); 182 185 user_path = strdup(myoptarg); 186 s+=2; 187 break; 188 case 'S': 189 if(screen_list->session_name) 190 free(screen_list->session_name); 191 screen_list->session_name = strdup(myoptarg); 183 192 s+=2; 184 193 break; … … 205 214 s+=2; 206 215 break; 216 case 'r': 217 forceattach = 1; 207 218 case 'R': 219 if(attach) 220 { 221 fprintf(stderr, "Attaching can only be requested once\n"); 222 return -1; 223 } 224 if(myoptarg) 225 { 226 session_name = strdup(myoptarg); 227 s+=1; 228 } 208 229 attach = 1; 209 230 s+=1; … … 242 263 return -1; 243 264 } 244 sockets = list_sockets(screen_list->socket_dir); 265 sockets = list_sockets(screen_list->socket_dir, session_name); 266 if(!screen_list->session_name) 267 screen_list->session_name = session_name; 268 else 269 free(session_name); 245 270 if(sockets && sockets[0]) 246 271 { … … 255 280 fprintf(stderr, "No socket found!\n"); 256 281 } 257 return -1; 282 if(forceattach) 283 return -1; 284 } 285 286 /* Build default session name */ 287 if(!screen_list->session_name) 288 { 289 char mypid[32]; /* FIXME Compute the length of PID_MAX ? */ 290 snprintf(mypid, 31, "%d", getpid()); 291 mypid[31]= '\0'; 292 screen_list->session_name = strdup(mypid); 293 if(!screen_list->session_name) 294 { 295 fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); 296 return -1; 297 } 258 298 } 259 299
Note: See TracChangeset
for help on using the changeset viewer.
