mirror of
https://github.com/fairyglade/ly
synced 2024-11-16 00:12:58 +00:00
fixed segfault at startup
This commit is contained in:
parent
25ad96ffd5
commit
01016a318b
@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -12,7 +13,7 @@
|
|||||||
#define LY_XSESSION_NAME "Name="
|
#define LY_XSESSION_NAME "Name="
|
||||||
|
|
||||||
// searches a folder
|
// searches a folder
|
||||||
void get_desktops(char* sessions_dir, struct delist_t* list, int* remote_count, short x)
|
short get_desktops(char* sessions_dir, struct delist_t* list, int* remote_count, short x)
|
||||||
{
|
{
|
||||||
/* xsession */
|
/* xsession */
|
||||||
FILE* file;
|
FILE* file;
|
||||||
@ -24,6 +25,11 @@ void get_desktops(char* sessions_dir, struct delist_t* list, int* remote_count,
|
|||||||
char* command;
|
char* command;
|
||||||
int count = *remote_count;
|
int count = *remote_count;
|
||||||
|
|
||||||
|
if(access(sessions_dir, F_OK) == -1 )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* reads xorg's desktop environments entries */
|
/* reads xorg's desktop environments entries */
|
||||||
dir = opendir(sessions_dir);
|
dir = opendir(sessions_dir);
|
||||||
|
|
||||||
@ -32,7 +38,7 @@ void get_desktops(char* sessions_dir, struct delist_t* list, int* remote_count,
|
|||||||
{
|
{
|
||||||
error_print(LY_ERR_DELIST);
|
error_print(LY_ERR_DELIST);
|
||||||
end_list(list, count);
|
end_list(list, count);
|
||||||
return;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cycles through the folder */
|
/* cycles through the folder */
|
||||||
@ -83,6 +89,8 @@ void get_desktops(char* sessions_dir, struct delist_t* list, int* remote_count,
|
|||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
*remote_count = count;
|
*remote_count = count;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns a list containing all the DE for all the display servers */
|
/* returns a list containing all the DE for all the display servers */
|
||||||
@ -90,10 +98,23 @@ struct delist_t* list_de(void)
|
|||||||
{
|
{
|
||||||
/* de list */
|
/* de list */
|
||||||
int count = 2;
|
int count = 2;
|
||||||
|
short errors = 0;
|
||||||
struct delist_t* list = init_list(count);
|
struct delist_t* list = init_list(count);
|
||||||
|
|
||||||
get_desktops(LY_PATH_XSESSIONS, list, &count, true);
|
if(get_desktops(LY_PATH_XSESSIONS, list, &count, true) != 0)
|
||||||
get_desktops(LY_PATH_WSESSIONS, list, &count, false);
|
{
|
||||||
|
++errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(get_desktops(LY_PATH_WSESSIONS, list, &count, false))
|
||||||
|
{
|
||||||
|
++errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(errors > 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
end_list(list, count);
|
end_list(list, count);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,11 @@ int main(void)
|
|||||||
char* cmd;
|
char* cmd;
|
||||||
/* gets desktop entries */
|
/* gets desktop entries */
|
||||||
de_list = list_de();
|
de_list = list_de();
|
||||||
|
|
||||||
|
if(de_list == NULL) {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
de_props = de_list->props;
|
de_props = de_list->props;
|
||||||
de_names = de_list->names;
|
de_names = de_list->names;
|
||||||
de_count = de_list->count;
|
de_count = de_list->count;
|
||||||
|
Loading…
Reference in New Issue
Block a user