Changeset 2488
- Timestamp:
- Jun 25, 2008, 12:33:40 AM (15 years ago)
- Location:
- neercs/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/attach.c
r2483 r2488 14 14 #include "neercs.h" 15 15 16 static char * build_socket_path(char *socket_dir )16 static char * build_socket_path(char *socket_dir, char *session_name) 17 17 { 18 18 char *path, *dir; … … 26 26 dir = "/tmp"; 27 27 if(path) 28 snprintf(path, PATH_MAX+1, "%s/neercs.% d.sock", dir, getpid());28 snprintf(path, PATH_MAX+1, "%s/neercs.%s.sock", dir, session_name); 29 29 return path; 30 30 } … … 46 46 47 47 myaddr.sun_family = AF_UNIX; 48 screen_list->socket_path = build_socket_path(screen_list->socket_path );48 screen_list->socket_path = build_socket_path(screen_list->socket_path, screen_list->session_name); 49 49 strncpy(myaddr.sun_path, screen_list->socket_path, sizeof(myaddr.sun_path) - 1); 50 50 unlink(myaddr.sun_path); … … 159 159 } 160 160 161 char ** list_sockets(char *socket_dir )161 char ** list_sockets(char *socket_dir, char *session_name) 162 162 { 163 163 char *pattern, *dir; … … 179 179 return globbuf.gl_pathv; 180 180 181 snprintf(pattern, PATH_MAX, "%s/neercs.*.sock", dir); 181 if(session_name && strlen(session_name)+strlen(dir)+13<PATH_MAX) 182 sprintf(pattern, "%s/neercs.%s.sock", dir, session_name); 183 else 184 snprintf(pattern, PATH_MAX, "%s/neercs.*.sock", dir); 182 185 pattern[PATH_MAX] = '\0'; 183 186 -
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 -
neercs/trunk/src/neercs.h
r2478 r2488 76 76 char *socket_path; /* Socket to ask for attaching */ 77 77 char *socket_dir; /* Where to create the socket */ 78 char *session_name; /* Name of the session */ 78 79 79 80 /* Lock */ … … 138 139 int create_socket(struct screen_list* screen_list); 139 140 int read_socket(struct screen_list* screen_list, cucul_canvas_t * cv, caca_display_t ** dp); 140 char ** list_sockets(char *socket_dir );141 char ** list_sockets(char *socket_dir, char *session_name); 141 142 142 143 /* Screens management */
Note: See TracChangeset
for help on using the changeset viewer.