Skip to content

Commit

Permalink
all SYSCONFDIR adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnorantGuru committed Sep 4, 2015
1 parent f1e892c commit 16a5f58
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/pref-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,9 @@ static void on_response( GtkDialog* dlg, int response, FMPrefDlg* user_data )
if ( root_set_change )
{
// task
xset_msg_dialog( GTK_WIDGET( dlg ), 0, _("Save Root Settings"), NULL, 0, _("You will now be asked for your root password to save the root settings for this user to a file in /etc/spacefm/ Supplying the password in the next window is recommended. Because SpaceFM runs some commands as root via su, these settings are best protected by root."), NULL, NULL );
char* msg = g_strdup_printf( _("You will now be asked for your root password to save the root settings for this user to a file in %s/spacefm/ Supplying the password in the next window is recommended. Because SpaceFM runs some commands as root via su, these settings are best protected by root."), SYSCONFDIR );
xset_msg_dialog( GTK_WIDGET( dlg ), 0, _("Save Root Settings"), NULL, 0, msg, NULL, NULL );
g_free( msg );
PtkFileTask* task = ptk_file_exec_new( _("Save Root Settings"), NULL, NULL,
NULL );
task->task->exec_command = g_strdup_printf( "echo" );
Expand Down
31 changes: 23 additions & 8 deletions src/ptk/ptk-location-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -2570,17 +2570,27 @@ static void on_restore( GtkMenuItem* item, VFSVolume* vol, GtkWidget* view2,

static void on_root_fstab( GtkMenuItem* item, GtkWidget* view )
{
xset_edit( view, "/etc/fstab", TRUE, FALSE );
char* fstab_path = g_build_filename( SYSCONFDIR, "fstab", NULL );
xset_edit( view, fstab_path, TRUE, FALSE );
g_free( fstab_path );
}

static void on_root_udevil( GtkMenuItem* item, GtkWidget* view )
{
if ( g_file_test( "/etc/udevil", G_FILE_TEST_IS_DIR ) )
xset_edit( view, "/etc/udevil/udevil.conf", TRUE, FALSE );
char* udevil_path = g_build_filename( SYSCONFDIR, "udevil", NULL );
char* udevil_conf = g_build_filename( SYSCONFDIR, "udevil", "udevil.conf",
NULL );
char* msg = g_strdup_printf(
_("The %s directory was not found. Is udevil installed?"),
udevil_path );
if ( g_file_test( udevil_path, G_FILE_TEST_IS_DIR ) )
xset_edit( view, udevil_conf, TRUE, FALSE );
else
xset_msg_dialog( view, GTK_MESSAGE_ERROR, _("Directory Missing"), NULL, 0,
_("The /etc/udevil directory was not found. Is udevil installed?"),
NULL, NULL );
xset_msg_dialog( view, GTK_MESSAGE_ERROR, _("Directory Missing"), NULL,
0, msg, NULL, NULL );
g_free( udevil_path );
g_free( udevil_conf );
g_free( msg );
}

static void on_restore_info( GtkMenuItem* item, GtkWidget* view, XSet* set2 )
Expand Down Expand Up @@ -2967,6 +2977,8 @@ static void on_prop( GtkMenuItem* item, VFSVolume* vol, GtkWidget* view2 )
char* info;
char* esc_path;

char* fstab_path = g_build_filename( SYSCONFDIR, "fstab", NULL );

char* base = g_path_get_basename( vol->device_file );
if ( base )
{
Expand All @@ -2987,15 +2999,17 @@ static void on_prop( GtkMenuItem* item, VFSVolume* vol, GtkWidget* view2 )

if ( uuid )
{
cmd = g_strdup_printf( "bash -c \"cat /etc/fstab | grep -e '%s' -e '%s'\"", uuid, vol->device_file );
cmd = g_strdup_printf( "bash -c \"cat %s | grep -e '%s' -e '%s'\"",
fstab_path, uuid, vol->device_file );
//cmd = g_strdup_printf( "bash -c \"cat /etc/fstab | grep -e ^[#\\ ]*UUID=$(/bin/ls -l /dev/disk/by-uuid | grep \\.\\./%s | sed 's/.* \\([a-fA-F0-9\-]*\\) -> \.*/\\1/')\\ */ -e '^[# ]*%s '\"", base, vol->device_file );
g_spawn_command_line_sync( cmd, &fstab, NULL, NULL, NULL );
g_free( cmd );
}

if ( !fstab )
{
cmd = g_strdup_printf( "bash -c \"cat /etc/fstab | grep '%s'\"", vol->device_file );
cmd = g_strdup_printf( "bash -c \"cat %s | grep '%s'\"",
fstab_path, vol->device_file );
//cmd = g_strdup_printf( "bash -c \"cat /etc/fstab | grep '^[# ]*%s '\"", vol->device_file );
g_spawn_command_line_sync( cmd, &fstab, NULL, NULL, NULL );
g_free( cmd );
Expand All @@ -3018,6 +3032,7 @@ static void on_prop( GtkMenuItem* item, VFSVolume* vol, GtkWidget* view2 )
}
}
}
g_free( fstab_path );

//printf("dev=%s\nuuid=%s\nfstab=%s\n", vol->device_file, uuid, fstab );
if ( uuid && fstab )
Expand Down
4 changes: 2 additions & 2 deletions src/vfs/vfs-file-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,15 +1613,15 @@ static void vfs_file_task_exec( char* src_file, VFSFileTask* task )
if ( this_user && this_user[0] != '\0' )
{
char* root_set_path= g_strdup_printf(
"/etc/spacefm/%s-as-root", this_user );
"%s/spacefm/%s-as-root", SYSCONFDIR, this_user );
write_root_settings( file, root_set_path );
g_free( root_set_path );
//g_free( this_user ); DON'T
}
else
{
char* root_set_path= g_strdup_printf(
"/etc/spacefm/%d-as-root", geteuid() );
"%s/spacefm/%d-as-root", SYSCONFDIR, geteuid() );
write_root_settings( file, root_set_path );
g_free( root_set_path );
}
Expand Down
5 changes: 4 additions & 1 deletion src/vfs/vfs-volume-hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,10 +1512,13 @@ gboolean vfs_volume_requires_eject( VFSVolume *vol )
static gboolean
fstab_open (gpointer *handle)
{
char* fstab_path;
#ifdef __FreeBSD__
return setfsent () == 1;
#else
*handle = fopen ("/etc/fstab", "r");
fstab_path = g_build_filename( SYSCONFDIR, "fstab", NULL );
*handle = fopen (fstab_path, "r");
g_free( fstab_path );
return *handle != NULL;
#endif
}
Expand Down
16 changes: 13 additions & 3 deletions src/vfs/vfs-volume-nohal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2637,21 +2637,28 @@ gboolean path_is_mounted_mtab( const char* mtab_file,
lines = NULL;
error = NULL;

char* mtab_path = g_build_filename( SYSCONFDIR, "mtab", NULL );

if ( mtab_file )
{
// read from a custom mtab file, eg ~/.mtab.fuseiso
if ( !g_file_get_contents( mtab_file, &contents, NULL, NULL ) )
{
g_free( mtab_path );
return FALSE;
}
}
else if ( !g_file_get_contents( MTAB, &contents, NULL, NULL ) )
{
if ( !g_file_get_contents( "/etc/mtab", &contents, NULL, &error ) )
if ( !g_file_get_contents( mtab_path, &contents, NULL, &error ) )
{
g_warning ("Error reading /etc/mtab: %s", error->message);
g_warning ("Error reading %s: %s", mtab_path, error->message);
g_error_free (error);
g_free( mtab_path );
return FALSE;
}
}
g_free( mtab_path );
lines = g_strsplit( contents, "\n", 0 );
for ( n = 0; lines[n] != NULL; n++ )
{
Expand Down Expand Up @@ -4243,13 +4250,16 @@ void unmount_if_mounted( VFSVolume* vol )
if ( !str )
return;

char* mtab_path = g_build_filename( SYSCONFDIR, "mtab", NULL );

char* mtab = MTAB;
if ( !g_file_test( mtab, G_FILE_TEST_EXISTS ) )
mtab = "/etc/mtab";
mtab = mtab_path;

char* line = g_strdup_printf( "grep -qs '^%s ' %s 2>/dev/null || exit\n%s\n",
vol->device_file, mtab, str );
g_free( str );
g_free( mtab_path );
printf( _("Unmount-If-Mounted: %s\n"), line );
exec_task( line, run_in_terminal );
g_free( line );
Expand Down

0 comments on commit 16a5f58

Please sign in to comment.