Change scr-bx to list the detached screens if more than one matches
This appears to be the original intention. It's certainly more friendly, anyway.
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
[Changes 1.2.2]
|
[Changes 1.2.2]
|
||||||
|
|
||||||
|
* scr-bx now lists the detached screens if there is more than one that matches
|
||||||
|
the string supplied by the user. (caf)
|
||||||
|
|
||||||
* Rename exported function move_to_abs_word() to move_to_word(). (caf)
|
* Rename exported function move_to_abs_word() to move_to_word(). (caf)
|
||||||
|
|
||||||
* Make "You can't hide an invisible window" message respect
|
* Make "You can't hide an invisible window" message respect
|
||||||
|
|||||||
@@ -228,55 +228,56 @@ void display_socket_list(const char *path, int unl, char *arg)
|
|||||||
|
|
||||||
char *find_detach_socket(const char *path, char *name)
|
char *find_detach_socket(const char *path, char *name)
|
||||||
{
|
{
|
||||||
|
const size_t path_len = strlen(path);
|
||||||
DIR *dptr;
|
DIR *dptr;
|
||||||
struct dirent *dir;
|
struct dirent *dir;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *ret;
|
char *ret = NULL;
|
||||||
|
char *path_name = NULL;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (!(dptr = opendir(path)))
|
if (!(dptr = opendir(path)))
|
||||||
return NULL;
|
return NULL;
|
||||||
ret = malloc(2000);
|
|
||||||
*ret = 0;
|
/* Count matching detach sockets */
|
||||||
while ((dir = readdir(dptr)))
|
while ((dir = readdir(dptr)))
|
||||||
{
|
{
|
||||||
*ret = 0;
|
|
||||||
if (!dir->d_ino)
|
if (!dir->d_ino)
|
||||||
continue;
|
continue;
|
||||||
if (dir->d_name[0] == '.')
|
if (dir->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
sprintf(ret, "%s/%s", path, dir->d_name);
|
|
||||||
if ((stat(ret, &st) == -1) || (st.st_uid != getuid()) || S_ISDIR(st.st_mode))
|
|
||||||
{
|
|
||||||
*ret = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (name && !strstr(dir->d_name, name))
|
if (name && !strstr(dir->d_name, name))
|
||||||
{
|
|
||||||
*ret = 0;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if ((st.st_mode & 0700) == 0600)
|
path_name = realloc(path_name, path_len + 2 + strlen(dir->d_name));
|
||||||
break;
|
sprintf(path_name, "%s/%s", path, dir->d_name);
|
||||||
count++;
|
|
||||||
*ret = 0;
|
if (stat(path_name, &st) == -1)
|
||||||
}
|
continue;
|
||||||
closedir(dptr);
|
|
||||||
if (ret && !*ret)
|
if (((st.st_mode & 0700) == 0600) && (st.st_uid == getuid()) && !S_ISDIR(st.st_mode))
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
free(ret);
|
free(ret);
|
||||||
ret = NULL;
|
ret = path_name;
|
||||||
|
path_name = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
free(path_name);
|
||||||
|
closedir(dptr);
|
||||||
|
|
||||||
switch (count)
|
switch (count)
|
||||||
{
|
{
|
||||||
|
default:
|
||||||
|
display_socket_list(path, 0, name);
|
||||||
|
/* fallthrough */
|
||||||
case 0:
|
case 0:
|
||||||
|
free(ret);
|
||||||
|
ret = NULL;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
display_socket_list(path, 0, name);
|
|
||||||
if (ret) free(ret);
|
|
||||||
ret = NULL;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user