Fix #244 Do not catch sigchld, let glib handle this internally

- TODO fix man page viewing.
This commit is contained in:
Dave Davenport 2015-10-12 08:12:25 +02:00
parent 56e023dcee
commit 4975704a05
4 changed files with 86 additions and 82 deletions

View File

@ -60,23 +60,23 @@ typedef struct _DmenuModePrivateData
static char **get_dmenu ( unsigned int *length ) static char **get_dmenu ( unsigned int *length )
{ {
const unsigned int buf_size = 1024; const unsigned int buf_size = 1024;
char buffer[buf_size]; char buffer[buf_size];
char **retv = NULL; char **retv = NULL;
char *buffer_end = NULL; char *buffer_end = NULL;
unsigned int rvlength = 1; unsigned int rvlength = 1;
*length = 0; *length = 0;
while ( ( buffer_end = fgets_s ( buffer, buf_size, stdin, (char) config.separator ) ) != NULL ) { while ( ( buffer_end = fgets_s ( buffer, buf_size, stdin, (char) config.separator ) ) != NULL ) {
if (rvlength < (*length + 2)) { if ( rvlength < ( *length + 2 ) ) {
rvlength *= 2; rvlength *= 2;
retv = g_realloc ( retv, ( rvlength ) * sizeof ( char* ) ); retv = g_realloc ( retv, ( rvlength ) * sizeof ( char* ) );
} }
size_t blength = buffer_end - &(buffer[0]); size_t blength = buffer_end - &( buffer[0] );
char *copy = g_malloc0( blength + 1 ); char *copy = g_malloc0 ( blength + 1 );
memcpy(copy, buffer, blength); memcpy ( copy, buffer, blength );
retv[( *length )] = copy; retv[( *length )] = copy;
retv[( *length ) + 1] = NULL; retv[( *length ) + 1] = NULL;
@ -87,7 +87,7 @@ static char **get_dmenu ( unsigned int *length )
return retv; return retv;
} }
} }
retv = g_realloc ( retv, ( *length + 1 ) * sizeof ( char* ) ); retv = g_realloc ( retv, ( *length + 1 ) * sizeof ( char* ) );
return retv; return retv;
} }
@ -311,7 +311,7 @@ int dmenu_switcher_dialog ( void )
char **tokens = tokenize ( select, config.case_sensitive ); char **tokens = tokenize ( select, config.case_sensitive );
unsigned int i = 0; unsigned int i = 0;
for ( i = 0; i < cmd_list_length; i++ ) { for ( i = 0; i < cmd_list_length; i++ ) {
if ( token_match ( tokens, cmd_list[i], is_not_ascii(cmd_list[i]), config.case_sensitive, 0, NULL ) ) { if ( token_match ( tokens, cmd_list[i], is_not_ascii ( cmd_list[i] ), config.case_sensitive, 0, NULL ) ) {
pd->selected_line = i; pd->selected_line = i;
break; break;
} }

View File

@ -322,7 +322,7 @@ typedef struct _SwitcherModePrivateData
} SwitcherModePrivateData; } SwitcherModePrivateData;
static int window_match ( char **tokens, __attribute__( ( unused ) ) const char *input, static int window_match ( char **tokens, __attribute__( ( unused ) ) const char *input,
__attribute__( ( unused) ) int not_ascii, __attribute__( ( unused ) ) int not_ascii,
int case_sensitive, unsigned int index, Switcher *sw ) int case_sensitive, unsigned int index, Switcher *sw )
{ {
SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data; SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data;
@ -339,19 +339,19 @@ static int window_match ( char **tokens, __attribute__( ( unused ) ) const char
// e.g. when searching 'title element' and 'class element' // e.g. when searching 'title element' and 'class element'
char *ftokens[2] = { tokens[j], NULL }; char *ftokens[2] = { tokens[j], NULL };
if ( !test && c->title[0] != '\0' ) { if ( !test && c->title[0] != '\0' ) {
test = token_match ( ftokens, c->title, is_not_ascii(c->title), case_sensitive, 0, NULL ); test = token_match ( ftokens, c->title, is_not_ascii ( c->title ), case_sensitive, 0, NULL );
} }
if ( !test && c->class[0] != '\0' ) { if ( !test && c->class[0] != '\0' ) {
test = token_match ( ftokens, c->class, is_not_ascii(c->class), case_sensitive, 0, NULL ); test = token_match ( ftokens, c->class, is_not_ascii ( c->class ), case_sensitive, 0, NULL );
} }
if ( !test && c->role[0] != '\0' ) { if ( !test && c->role[0] != '\0' ) {
test = token_match ( ftokens, c->role, is_not_ascii(c->role), case_sensitive, 0, NULL ); test = token_match ( ftokens, c->role, is_not_ascii ( c->role ), case_sensitive, 0, NULL );
} }
if ( !test && c->name[0] != '\0' ) { if ( !test && c->name[0] != '\0' ) {
test = token_match ( ftokens, c->name, is_not_ascii(c->name), case_sensitive, 0, NULL ); test = token_match ( ftokens, c->name, is_not_ascii ( c->name ), case_sensitive, 0, NULL );
} }
if ( test == 0 ) { if ( test == 0 ) {

View File

@ -45,8 +45,8 @@ static int stored_argc = 0;
static char **stored_argv = NULL; static char **stored_argv = NULL;
// TODO: is this safe? // TODO: is this safe?
#define NON_ASCII_NON_NULL( x ) ( ((x) < 0) ) #define NON_ASCII_NON_NULL( x ) ( ( ( x ) < 0 ) )
#define ASCII_NON_NULL( x ) ( ((x) > 0) ) #define ASCII_NON_NULL( x ) ( ( ( x ) > 0 ) )
void cmd_set_arguments ( int argc, char **argv ) void cmd_set_arguments ( int argc, char **argv )
{ {
@ -334,39 +334,43 @@ int find_arg_char ( const char * const key, char *val )
/* /*
* auxiliary to `fuzzy-token-match' below; * auxiliary to `fuzzy-token-match' below;
*/ */
static void advance_unicode_glyph( char** token_in, char** input_in ) { static void advance_unicode_glyph ( char** token_in, char** input_in )
// determine the end of the glyph from token {
// determine the end of the glyph from token
char *token = *token_in; char *token = *token_in;
char *input = *input_in; char *input = *input_in;
while (NON_ASCII_NON_NULL(*token)) { while ( NON_ASCII_NON_NULL ( *token ) ) {
token++; token++;
} }
// now we know the glyph length, we can scan for that substring in input // now we know the glyph length, we can scan for that substring in input
// temporarily add a null-terminator in case: // temporarily add a null-terminator in case:
char glyph_end = *token; char glyph_end = *token;
*token = 0; *token = 0;
char *match = strstr(input, *token_in); char *match = strstr ( input, *token_in );
*token = glyph_end; *token = glyph_end;
if ( match ) { if ( match ) {
*token_in = token; *token_in = token;
*input_in = match; *input_in = match;
} else { }
// wind input along to the end so that we fail else {
while ( **input_in ) (*input_in)++; // wind input along to the end so that we fail
} while ( **input_in ) {
( *input_in )++;
}
}
} }
/** /**
* Shared 'token_match' function. * Shared 'token_match' function.
* Matches tokenized. * Matches tokenized.
*/ */
static int fuzzy_token_match ( char **tokens, const char *input, __attribute__( (unused) ) int not_ascii, int case_sensitive ) static int fuzzy_token_match ( char **tokens, const char *input, __attribute__( ( unused ) ) int not_ascii, int case_sensitive )
{ {
int match = 1; int match = 1;
// Do a tokenized match. // Do a tokenized match.
@ -378,46 +382,49 @@ static int fuzzy_token_match ( char **tokens, const char *input, __attribute__(
if ( tokens ) { if ( tokens ) {
char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : (char *) input; char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : (char *) input;
for ( int j = 0; match && tokens[j]; j++ ) { for ( int j = 0; match && tokens[j]; j++ ) {
char *t = compk; char *t = compk;
char *token = tokens[j]; char *token = tokens[j];
while (*t && *token) { while ( *t && *token ) {
if ( *token > 0 ) // i.e. we are at an ascii codepoint if ( *token > 0 ) { // i.e. we are at an ascii codepoint
{ if ( ( case_sensitive && ( *t == *token ) ) ||
if ( ( case_sensitive && (*t == *token)) || ( !case_sensitive && ( tolower ( *t ) == tolower ( *token ) ) ) ) {
(!case_sensitive && (tolower(*t) == tolower(*token))) ) token++;
token++; }
} }
else else{
{ // we are not at an ascii codepoint, and so we need to do something
// we are not at an ascii codepoint, and so we need to do something // complicated
// complicated advance_unicode_glyph ( &token, &t );
advance_unicode_glyph( &token, &t );
} }
t++; t++;
} }
match = !(*token); match = !( *token );
}
if ( not_ascii ) {
g_free ( compk );
} }
if (not_ascii) g_free ( compk );
} }
return match; return match;
} }
static int normal_token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive ) static int normal_token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive )
{ {
int match = 1; int match = 1;
// Do a tokenized match. // Do a tokenized match.
if ( tokens ) { if ( tokens ) {
char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : (char *) input; char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : (char *) input;
char *(*comparison)(const char *, const char *); char *( *comparison )( const char *, const char * );
comparison = (case_sensitive || not_ascii) ? strstr : strcasestr; comparison = ( case_sensitive || not_ascii ) ? strstr : strcasestr;
for ( int j = 0; match && tokens[j]; j++ ) { for ( int j = 0; match && tokens[j]; j++ ) {
match = (comparison( compk, tokens[j] ) != NULL ); match = ( comparison ( compk, tokens[j] ) != NULL );
} }
if (not_ascii) g_free ( compk ); if ( not_ascii ) {
g_free ( compk );
}
} }
return match; return match;
@ -434,7 +441,9 @@ static int glob_token_match ( char **tokens, const char *input, int not_ascii, i
match = g_pattern_match_simple ( tokens[j], compk ); match = g_pattern_match_simple ( tokens[j], compk );
} }
} }
if (not_ascii) g_free ( compk ); if ( not_ascii ) {
g_free ( compk );
}
return match; return match;
} }
@ -577,9 +586,11 @@ void config_sanity_check ( )
int is_not_ascii ( const char * str ) int is_not_ascii ( const char * str )
{ {
while (ASCII_NON_NULL(*str)) { while ( ASCII_NON_NULL ( *str ) ) {
str++; str++;
} }
if (*str) return 1; if ( *str ) {
return 0; return 1;
}
return 0;
} }

View File

@ -951,13 +951,13 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
.border = config.padding + config.menu_bw .border = config.padding + config.menu_bw
}; };
// Request the lines to show. // Request the lines to show.
state.lines = sw->get_data ( &( state.num_lines ), sw ); state.lines = sw->get_data ( &( state.num_lines ), sw );
state.lines_not_ascii = g_malloc0_n( state.num_lines, sizeof( int ) ); state.lines_not_ascii = g_malloc0_n ( state.num_lines, sizeof ( int ) );
// find out which lines contain non-ascii codepoints, so we can be faster in some cases. // find out which lines contain non-ascii codepoints, so we can be faster in some cases.
for (unsigned int line = 0; state.lines[line]; line++) { for ( unsigned int line = 0; state.lines[line]; line++ ) {
state.lines_not_ascii[line] = is_not_ascii(state.lines[line]); state.lines_not_ascii[line] = is_not_ascii ( state.lines[line] );
} }
if ( next_pos ) { if ( next_pos ) {
@ -1802,7 +1802,6 @@ static gpointer rofi_signal_handler_process ( gpointer arg )
sigaddset ( &set, SIGHUP ); sigaddset ( &set, SIGHUP );
sigaddset ( &set, SIGINT ); sigaddset ( &set, SIGINT );
sigaddset ( &set, SIGUSR1 ); sigaddset ( &set, SIGUSR1 );
sigaddset ( &set, SIGCHLD );
// loop forever. // loop forever.
while ( 1 ) { while ( 1 ) {
siginfo_t info; siginfo_t info;
@ -1823,11 +1822,6 @@ static gpointer rofi_signal_handler_process ( gpointer arg )
// Close my end and exit. // Close my end and exit.
g_thread_exit ( NULL ); g_thread_exit ( NULL );
} }
else if ( sig == SIGCHLD ) {
while ( 0 < waitpid ( -1, NULL, WNOHANG ) ) {
;
}
}
} }
} }
} }
@ -1915,7 +1909,6 @@ static GThread *setup_signal_thread ( int *fd )
sigaddset ( &set, SIGHUP ); sigaddset ( &set, SIGHUP );
sigaddset ( &set, SIGINT ); sigaddset ( &set, SIGINT );
sigaddset ( &set, SIGUSR1 ); sigaddset ( &set, SIGUSR1 );
sigaddset ( &set, SIGCHLD );
sigprocmask ( SIG_BLOCK, &set, NULL ); sigprocmask ( SIG_BLOCK, &set, NULL );
// Create signal handler process. // Create signal handler process.
// This will use sigwaitinfo to read signals and forward them back to the main thread again. // This will use sigwaitinfo to read signals and forward them back to the main thread again.