Opened 13 years ago

Closed 13 years ago

#2226 closed Bug (invalid)

Remove HOME and let getpwuid does the work in getHomeDir()...

Reported by: mezz Owned by: charles
Priority: Lowest Milestone: None Set
Component: libtransmission Version: 1.72
Severity: Minor Keywords:
Cc:

Description

It is my very first time to use transmission-daemon. I have written a rc (startup) script in FreeBSD for I can add it in port/package, because I get a lot of request every week. I was puzzled to see when transmission-daemon picked up HOME as /root while it was running as 'transmission' user. It causes storage config data in /root/.config and has /root/Downloads by default.

I dig in the source code and found getHomeDir() in libtransmission/platform.c. I have added three printf() to get info of getuid(), getgid() and home. Without patch, it looks like this:

# ./transmission start
Starting transmission.
getuid: 919
getgid: 919
HOME: /root

In my passwd has this:

# grep trans /etc/passwd
transmission:*:919:919:Transmission Daemon User:/usr/local/etc/transmission/home:/usr/sbin/nologin

I have asked FreeBSD community and they said that script will always set HOME to /root, because transmission-daemon runs as root at first then switch to 'transmission' user by su(1) from the script. marcus also said that can use getpwuid() then I realized that getHomeDir() already has getpwuid() in it. I just tweak the code by remove getenv("HOME"); and let getpwuid() does the work. The result I get this now:

# ./transmission start
Starting transmission.
getuid: 919
getgid: 919
HOME: /usr/local/etc/transmission/home

Attaching a patch.. With this patch, it matches the behavior to TRANSMISSION_HOME by read in tr_getDefaultConfigDir().

Look forward for you to accept chroot patch in #2189 if it's good. :-)

Attachments (1)

patch-libtransmission_platform.c (1.1 KB) - added by mezz 13 years ago.

Download all attachments as: .zip

Change History (7)

Changed 13 years ago by mezz

comment:1 Changed 13 years ago by mezz

By the way, I am wondering why don't daemon create ~/Downloads if it does not exist by use tr_mkdirp() just like you did with the config directory? By default, it throws an error of directory does not exist when I added a torrent. Umm, I probably should create another ticket for this?

comment:2 Changed 13 years ago by charles

mezz: the problem with this diff is that it breaks behavior for end users of the non-daemon clients, who expect $HOME to work.

Instead of ignoring $HOME, why not have the script pass in "-g" to override the default config directory?

comment:3 Changed 13 years ago by mezz

Because I don't know if there is any more for $HOME. Are -g and -w the only part that use $HOME in daemon?

comment:4 Changed 13 years ago by charles

  • Milestone changed from 1.80 to None Set

getHomeDir() is used for three things:

  • tr_getDefaultConfigDir() - can override with -g
  • tr_getDefaultDownloadDir() - can override with -w
  • tr_getClutchDir() - can override with CLUTCH_HOME, TRANSMISSION_WEB_HOME, and XDG_DATA_HOME

So I think that -g will fix it for you.

comment:5 Changed 13 years ago by charles

(about the above: any of the three environment variables are used by tr_getClutchDir() in preference to tr_getHomeDir(). It's the fourth in line, after all the other options fail.

comment:6 Changed 13 years ago by mezz

  • Priority changed from Normal to Lowest
  • Resolution set to invalid
  • Severity changed from Normal to Minor
  • Status changed from new to closed

Ok thanks, I will remove this patch from package and use -g/-w.

Note: See TracTickets for help on using tickets.