+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/fvwm/environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ are the following:
option is given.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><envar>FVWM3_LOGFILE</envar></term>
<listitem>
<para>Used to determine the path and filename to log debug information
from fvwm3.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><envar>FVWM_MODULEDIR</envar></term>
<listitem>
Expand Down
18 changes: 3 additions & 15 deletions fvwm/fvwm3.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_GETPWUID
# include <pwd.h>
#endif
#if HAVE_SYS_SYSTEMINFO_H
/* Solaris has sysinfo instead of gethostname. */
#include <sys/systeminfo.h>
Expand All @@ -49,6 +46,7 @@
#include "libs/FRenderInit.h"
#include "libs/charmap.h"
#include "libs/wcontext.h"
#include "libs/getpwuid.h"
#include "fvwm.h"
#include "externs.h"
#include "cursor.h"
Expand Down Expand Up @@ -122,7 +120,7 @@ static char l_g_bits[] =
static char s_g_bits[] =
{0x01, 0x02, 0x04, 0x08};

static char *home_dir;
static const char *home_dir;

static volatile sig_atomic_t fvwmRunState = FVWM_RUNNING;

Expand Down Expand Up @@ -1790,17 +1788,7 @@ int main(int argc, char **argv)
flib_putenv("FVWM_MODULEDIR", "FVWM_MODULEDIR=" FVWM_MODULEDIR);

/* Figure out user's home directory */
home_dir = getenv("HOME");
#ifdef HAVE_GETPWUID
if (home_dir == NULL)
{
struct passwd* pw = getpwuid(getuid());
if (pw != NULL)
{
home_dir = fxstrdup(pw->pw_dir);
}
}
#endif
home_dir = find_home_dir();
if (home_dir == NULL)
{
home_dir = "/"; /* give up and use root dir */
Expand Down
6 changes: 3 additions & 3 deletions libs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ libfvwm3_a_SOURCES = \
PictureUtils.h Rectangles.h Strings.h System.h Target.h WinMagic.h \
XError.h XResource.h charmap.h defaults.h envvar.h fio.h flist.h fqueue.h \
fsm.h ftime.h fvwm_sys_stat.h fvwmlib.h fvwmrect.h fvwmsignal.h \
gravity.c gravity.h lang-strings.h log.h modifiers.h queue.h safemalloc.h \
setpgrp.h strlcpy.h timeout.h vpacket.h wcontext.h wild.h \
gravity.c gravity.h getpwuid.h lang-strings.h log.h modifiers.h queue.h \
safemalloc.h setpgrp.h strlcpy.h timeout.h vpacket.h wcontext.h wild.h \
\
BidiJoin.c Flocale.c PictureUtils.c FScreen.c Graphics.c \
PictureGraphics.c Bindings.c FlocaleCharset.c Parse.c \
Expand All @@ -26,7 +26,7 @@ libfvwm3_a_SOURCES = \
fvwmrect.c FRenderInit.c safemalloc.c FBidi.c \
wild.c Grab.c Event.c ClientMsg.c setpgrp.c FShape.c \
FGettext.c Rectangles.c timeout.c flist.c charmap.c wcontext.c \
modifiers.c fsm.c FTips.c fio.c fvwmlib3.c strlcpy.c
modifiers.c fsm.c FTips.c fio.c fvwmlib3.c strlcpy.c getpwuid.c

libfvwm3_a_LIBADD = @LIBOBJS@

Expand Down
74 changes: 74 additions & 0 deletions libs/getpwuid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see: <http://www.gnu.org/licenses/>
*/

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "safemalloc.h"
#include "getpwuid.h"

const char
*find_home_dir(void)
{
struct passwd *pw;
const char *home;

home = getenv("HOME");
if (home == NULL || *home == '\0') {
pw = getpwuid(getuid());
if (pw != NULL)
home = pw->pw_dir;
else
home = NULL;
}

return (home);
}

const char *
expand_path(const char *path)
{
char *expanded, *name;
const char *end, *value, *home;

home = find_home_dir();

if (strncmp(path, "~/", 2) == 0) {
if (home == NULL)
return (NULL);
xasprintf(&expanded, "%s%s", home, path + 1);
return (expanded);
}

if (*path == '$') {
end = strchr(path, '/');
if (end == NULL)
name = fxstrdup(path + 1);
else
name = strndup(path + 1, end - path - 1);
value = getenv(name);
free(name);
if (value == NULL)
return (NULL);
if (end == NULL)
end = "";
xasprintf(&expanded, "%s%s", value, end);
return (expanded);
}

return (fxstrdup(path));
}
25 changes: 25 additions & 0 deletions libs/getpwuid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see: <http://www.gnu.org/licenses/>
*/

#ifndef FVWM_GETPWUID_H
#define FVWM_GETPWUID_H

#ifdef HAVE_GETPWUID
# include <pwd.h>
#endif

const char *find_home_dir(void);
const char *expand_path(const char *);

#endif
20 changes: 18 additions & 2 deletions libs/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <unistd.h>

#include "fvwmlib.h"
#include "getpwuid.h"
#include "log.h"

static FILE *log_file;
Expand All @@ -46,17 +47,32 @@ log_set_level(int ll)
void
log_open(void)
{
char *path = "fvwm3-output.log";
char *path = fxstrdup(FVWM3_LOGFILE_DEFAULT);

if (getenv("FVWM3_LOGFILE")) {
const char *expanded_path;

free(path);
path = getenv("FVWM3_LOGFILE");
expanded_path = expand_path(path);

path = fxstrdup(expanded_path);
free((char *)expanded_path);
}

if (log_level == 0)
return;
log_close();

log_file = fopen(path, "a");
if (log_file == NULL)
if (log_file == NULL) {
free(path);
return;
}

setvbuf(log_file, NULL, _IOLBF, 0);

free(path);
}

/* Toggle logging. */
Expand Down
1 change: 1 addition & 0 deletions libs/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _LOG_H

#define printflike(a, b) __attribute__ ((format (printf, a, b)))
#define FVWM3_LOGFILE_DEFAULT "fvwm3-output.log"

void log_set_level(int);
int log_get_level(void);
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载