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 )
{
const unsigned int buf_size = 1024;
char buffer[buf_size];
char **retv = NULL;
char *buffer_end = NULL;
unsigned int rvlength = 1;
char buffer[buf_size];
char **retv = NULL;
char *buffer_end = NULL;
unsigned int rvlength = 1;
*length = 0;
while ( ( buffer_end = fgets_s ( buffer, buf_size, stdin, (char) config.separator ) ) != NULL ) {
if (rvlength < (*length + 2)) {
rvlength *= 2;
retv = g_realloc ( retv, ( rvlength ) * sizeof ( char* ) );
if ( rvlength < ( *length + 2 ) ) {
rvlength *= 2;
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 );
memcpy(copy, buffer, blength);
char *copy = g_malloc0 ( blength + 1 );
memcpy ( copy, buffer, blength );
retv[( *length )] = copy;
retv[( *length ) + 1] = NULL;
@ -87,7 +87,7 @@ static char **get_dmenu ( unsigned int *length )
return retv;
}
}
retv = g_realloc ( retv, ( *length + 1 ) * sizeof ( char* ) );
retv = g_realloc ( retv, ( *length + 1 ) * sizeof ( char* ) );
return retv;
}
@ -311,7 +311,7 @@ int dmenu_switcher_dialog ( void )
char **tokens = tokenize ( select, config.case_sensitive );
unsigned int i = 0;
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;
break;
}

View File

@ -322,7 +322,7 @@ typedef struct _SwitcherModePrivateData
} SwitcherModePrivateData;
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 )
{
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'
char *ftokens[2] = { tokens[j], NULL };
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' ) {
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' ) {
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' ) {
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 ) {

View File

@ -45,8 +45,8 @@ static int stored_argc = 0;
static char **stored_argv = NULL;
// TODO: is this safe?
#define NON_ASCII_NON_NULL( x ) ( ((x) < 0) )
#define ASCII_NON_NULL( x ) ( ((x) > 0) )
#define NON_ASCII_NON_NULL( x ) ( ( ( x ) < 0 ) )
#define ASCII_NON_NULL( x ) ( ( ( x ) > 0 ) )
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;
*/
static void advance_unicode_glyph( char** token_in, char** input_in ) {
// determine the end of the glyph from token
static void advance_unicode_glyph ( char** token_in, char** input_in )
{
// determine the end of the glyph from token
char *token = *token_in;
char *input = *input_in;
char *token = *token_in;
char *input = *input_in;
while (NON_ASCII_NON_NULL(*token)) {
token++;
}
while ( NON_ASCII_NON_NULL ( *token ) ) {
token++;
}
// now we know the glyph length, we can scan for that substring in input
// temporarily add a null-terminator in case:
char glyph_end = *token;
*token = 0;
char *match = strstr(input, *token_in);
*token = glyph_end;
// now we know the glyph length, we can scan for that substring in input
// temporarily add a null-terminator in case:
char glyph_end = *token;
*token = 0;
char *match = strstr ( input, *token_in );
*token = glyph_end;
if ( match ) {
*token_in = token;
*input_in = match;
} else {
// wind input along to the end so that we fail
while ( **input_in ) (*input_in)++;
}
if ( match ) {
*token_in = token;
*input_in = match;
}
else {
// wind input along to the end so that we fail
while ( **input_in ) {
( *input_in )++;
}
}
}
/**
* Shared 'token_match' function.
* 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.
@ -378,46 +382,49 @@ static int fuzzy_token_match ( char **tokens, const char *input, __attribute__(
if ( tokens ) {
char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : (char *) input;
for ( int j = 0; match && tokens[j]; j++ ) {
char *t = compk;
char *token = tokens[j];
char *t = compk;
char *token = tokens[j];
while (*t && *token) {
if ( *token > 0 ) // i.e. we are at an ascii codepoint
{
if ( ( case_sensitive && (*t == *token)) ||
(!case_sensitive && (tolower(*t) == tolower(*token))) )
token++;
while ( *t && *token ) {
if ( *token > 0 ) { // i.e. we are at an ascii codepoint
if ( ( case_sensitive && ( *t == *token ) ) ||
( !case_sensitive && ( tolower ( *t ) == tolower ( *token ) ) ) ) {
token++;
}
}
else
{
// we are not at an ascii codepoint, and so we need to do something
// complicated
advance_unicode_glyph( &token, &t );
else{
// we are not at an ascii codepoint, and so we need to do something
// complicated
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;
}
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.
if ( tokens ) {
char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : (char *) input;
char *(*comparison)(const char *, const char *);
comparison = (case_sensitive || not_ascii) ? strstr : strcasestr;
for ( int j = 0; match && tokens[j]; j++ ) {
match = (comparison( compk, tokens[j] ) != NULL );
}
if (not_ascii) g_free ( compk );
char *compk = not_ascii ? token_collate_key ( input, case_sensitive ) : (char *) input;
char *( *comparison )( const char *, const char * );
comparison = ( case_sensitive || not_ascii ) ? strstr : strcasestr;
for ( int j = 0; match && tokens[j]; j++ ) {
match = ( comparison ( compk, tokens[j] ) != NULL );
}
if ( not_ascii ) {
g_free ( compk );
}
}
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 );
}
}
if (not_ascii) g_free ( compk );
if ( not_ascii ) {
g_free ( compk );
}
return match;
}
@ -577,9 +586,11 @@ void config_sanity_check ( )
int is_not_ascii ( const char * str )
{
while (ASCII_NON_NULL(*str)) {
str++;
}
if (*str) return 1;
return 0;
while ( ASCII_NON_NULL ( *str ) ) {
str++;
}
if ( *str ) {
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
};
// Request the lines to show.
state.lines = sw->get_data ( &( state.num_lines ), sw );
state.lines_not_ascii = g_malloc0_n( state.num_lines, sizeof( int ) );
state.lines = sw->get_data ( &( state.num_lines ), sw );
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.
for (unsigned int line = 0; state.lines[line]; line++) {
state.lines_not_ascii[line] = is_not_ascii(state.lines[line]);
for ( unsigned int line = 0; state.lines[line]; line++ ) {
state.lines_not_ascii[line] = is_not_ascii ( state.lines[line] );
}
if ( next_pos ) {
@ -1802,7 +1802,6 @@ static gpointer rofi_signal_handler_process ( gpointer arg )
sigaddset ( &set, SIGHUP );
sigaddset ( &set, SIGINT );
sigaddset ( &set, SIGUSR1 );
sigaddset ( &set, SIGCHLD );
// loop forever.
while ( 1 ) {
siginfo_t info;
@ -1823,11 +1822,6 @@ static gpointer rofi_signal_handler_process ( gpointer arg )
// Close my end and exit.
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, SIGINT );
sigaddset ( &set, SIGUSR1 );
sigaddset ( &set, SIGCHLD );
sigprocmask ( SIG_BLOCK, &set, NULL );
// Create signal handler process.
// This will use sigwaitinfo to read signals and forward them back to the main thread again.