/dev/stderr gets unlinked 8]
Hi,
In the bad days of devfsd, no user program could remove /dev/stderr (bacause fs didn't allow for that).
But I switched to udev sometime ago.
Today I discovered that my mysqld was happily unlinking it and recreating as regular file in /dev (I pass --log=/dev/stderr to mysqld).
Can I make /dev/stderr non-unlink-able?
--
vda
Quoted 1 line
Can I make
/dev/stderrnon-unlink-able?
Take a look to
$ man chattr # chattr +i /dev/stderr
if you are using a ext2/3 filesystem. If not, maybe your filesystem has some similar functionality.
--
Aurelien Degremont
Quoted 9 lines · Aurelien Degremont
Quoted 1 line
Can I make
/dev/stderrnon-unlink-able?Take a look to
$ man chattr # chattr +i /dev/stderrif you are using a ext2/3 filesystem. If not, maybe your filesystem has some similar functionality.
I have ramfs based /dev, which I mount early over /dev (from initrd, in fact). On-disk /dev/ is empty.
--
vda
Quoted 11 lines
Hi,
In the bad days of devfsd, no user program could remove
/dev/stderr(bacause fs didn't allow for that).But I switched to udev sometime ago.
Today I discovered that my mysqld was happily unlinking it and recreating as regular file in /dev (I pass --log=/dev/stderr to mysqld).
Quoted 8 lines
Can I make
/dev/stderrnon-unlink-able?
--
vda
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
You could run mysql as non-privileged user or try something like --log=/proc/self/fd/2
-Christian
Quoted 20 lines · Christian
Quoted 11 lines
Hi,
In the bad days of devfsd, no user program could remove
/dev/stderr(bacause fs didn't allow for that).But I switched to udev sometime ago.
Today I discovered that my mysqld was happily unlinking it and recreating as regular file in /dev (I pass --log=/dev/stderr to mysqld).
Quoted 8 lines
Can I make
/dev/stderrnon-unlink-able?
--
vda
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 2 lines
You could run mysql as non-privileged user or try something like --log=/proc/self/fd/2
Mysql people are strange. For example, their daemon does not want to die on SIGTERM, this makes it harder to run it under daemontools.
Also it drops privileges BEFORE it opens logfiles (--log=xxx). I cannot get it to log stuff on stderr:
echo "* Starting mysqld"
env - \
setuidgid root \
mysqld \
--defaults-file="$PWD/my.cnf" \
--user="$user" \
--datadir="$var/data" \
--tmpdir="$var/tmp" \
--socket="$PWD/mysql.socket" \
--pid-file="$PWD/mysql.pid" \
--skip-name-resolve \
--skip-innodb \
--skip-ndbcluster \
--skip-networking \
--log=/proc/self/fd/2 \
--log-slow-queries=/proc/self/fd/2 \Those last two options don't work:
mysqld: File '/proc/self/fd/2' not found (Errcode: 13)
Oh well....
--
vda
Quoted 2 lines · Denis Vlasenko
Mysql people are strange. For example, their daemon does not want to die on SIGTERM, this makes it harder to run it under daemontools.
Well, daemontools are equally strange ;-))
Quoted 20 lines
Also it drops privileges BEFORE it opens logfiles (--log=xxx). I cannot get it to log stuff on stderr:
echo "* Starting mysqld"
env - \
setuidgid root \mysqld \ --defaults-file="$PWD/my.cnf" \ --user="$user" \ --datadir="$var/data" \ --tmpdir="$var/tmp" \ --socket="$PWD/mysql.socket" \ --pid-file="$PWD/mysql.pid" \ --skip-name-resolve \ --skip-innodb \ --skip-ndbcluster \ --skip-networking \ --log=/proc/self/fd/2 \ --log-slow-queries=/proc/self/fd/2 \
Quoted 3 lines
Those last two options don't work:
mysqld: File '
/proc/self/fd/2' not found (Errcode: 13)
any good daemon closes stdout, stderr, stdin and does chdir(/) on startup. msqld might do so as well.
Signature · 3 lines
Stefan Seyfried \ "I didn't want to write for pay. I QA / R&D Team Mobile Devices \ wanted to be paid for what I write." SUSE LINUX Products GmbH, Nürnberg \ -- Leonard Cohen
Quoted 1 line · Stefan Seyfried
any good daemon closes stdout, stderr, stdin
A real good daemon would redirect them to /dev/null.
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 5 lines · Andreas Schwab
Quoted 1 line · Stefan Seyfried
any good daemon closes stdout, stderr, stdin
A real good daemon would redirect them to
/dev/null.
Yeah, yeah, let's first close stderr, and then proceed and add some code to handle command line --log=file, and to do logging to that file.
Why good ol' fprintf(stderr,...) isn't enough? Why do you want to complicate things?
What's so hard in doing "daemon 2>/dev/null &" if you don't want to save log?
--
vda
Quoted 11 lines · Denis Vlasenko
Quoted 5 lines · Andreas Schwab
Quoted 1 line · Stefan Seyfried
any good daemon closes stdout, stderr, stdin
A real good daemon would redirect them to
/dev/null.Yeah, yeah, let's first close stderr, and then proceed and add some code to handle command line --log=file, and to do logging to that file.
Quoted 7 lines
Why good ol'
fprintf(stderr,...)isn't enough? Why do you want to complicate things?What's so hard in doing "daemon 2>/dev/null &" if you don't want to save log?
--
vda
The daemon needs to have the standard input closed as well as any I/O connection to a possible terminal. Just closing standard input, allows a dup() in rogue code to recreate it. Basically, file-descriptors 0, 1, and 2, need to be USED and used for something else (like open /dev/null or open "/"). That's how you prevent rogue code, inserted via overflow or other means, from obtaining control of your system. Good daemons also use system services to write messages to log files. They don't make their own, which is one of the reasons why early versions of sendmail were not considered "good" daemons.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.15.4 on an i686 machine (5589.54 BogoMips). Warning : 98.36% of all statistics are fiction, book release in April. _
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
Quoted 22 lines · linux-os (Dick Johnson)
Quoted 11 lines · Denis Vlasenko
Quoted 5 lines · Andreas Schwab
Quoted 1 line · Stefan Seyfried
any good daemon closes stdout, stderr, stdin
A real good daemon would redirect them to
/dev/null.Yeah, yeah, let's first close stderr, and then proceed and add some code to handle command line --log=file, and to do logging to that file.
Quoted 7 lines
Why good ol'
fprintf(stderr,...)isn't enough? Why do you want to complicate things?What's so hard in doing "daemon 2>/dev/null &" if you don't want to save log?
--
vda
Quoted 7 lines
The daemon needs to have the standard input closed as well as any I/O connection to a possible terminal. Just closing standard input, allows a
dup()in rogue code to recreate it. Basically, file-descriptors 0, 1, and 2, need to be USED and used for something else (like open/dev/nullor open "/"). That's how you prevent rogue code, inserted via overflow or other means, from obtaining control of your system.
... and everything described above is perfectly doable by shell mechanisms (like redirections) prior to strting daemon, right? --
vda
Quoted 5 lines
Quoted 2 lines
any good daemon closes stdout, stderr, stdin
A real good daemon would redirect them to
/dev/null.
and writes to /var/log/mysql/...
Jan Engelhardt
Quoted 5 lines · Jan Engelhardt
Quoted 3 lines
Quoted 1 line
any good daemon closes stdout, stderr, stdin
A real good daemon would redirect them to
/dev/null.and writes to
/var/log/mysql/...
And has log rotation. Apache has log rotation. Squid has log rotation.
Why they all need to have log rotation code? I forced them all to just write log to stderr, and multilog from daemontools does the logging (with rotation and postprocessing (for example, feeds Squid log into Mysql db)) just fine.
But we digress. Is there any magic (mount --bind?) to make /dev/stderr undestructible?
--
vda
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
any good daemon closes stdout, stderr, stdin
A real good daemon would redirect them to
/dev/null.and writes to
/var/log/mysql/...And has log rotation. Apache has log rotation. Squid has log rotation.
Why they all need to have log rotation code? I forced them all to just
I dunno. SUSE Linux (no advertisement intended) uses a global solution - "logrotate" rather than using each project's own logrotation.
Quoted 6 lines
write log to stderr, and multilog from daemontools does the logging (with rotation and postprocessing (for example, feeds Squid log into Mysql db)) just fine.
But we digress. Is there any magic (mount --bind?) to make
/dev/stderrundestructible?
If not, you could write an LSM that prohibits unlinking /dev/stderr.
Jan Engelhardt
Signature · 1 line
| Software Engineer and Linux/Unix Network Administrator
Quoted 17 lines · Jan Engelhardt
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
any good daemon closes stdout, stderr, stdin
A real good daemon would redirect them to
/dev/null.and writes to
/var/log/mysql/...And has log rotation. Apache has log rotation. Squid has log rotation.
Why they all need to have log rotation code? I forced them all to just
I dunno. SUSE Linux (no advertisement intended) uses a global solution - "logrotate" rather than using each project's own logrotation.
Quoted 4 lines
write log to stderr, and multilog from daemontools does the logging (with rotation and postprocessing (for example, feeds Squid log into Mysql db)) just fine.
Quoted 6 lines
Quoted 2 lines
But we digress. Is there any magic (mount --bind?) to make
/dev/stderrundestructible?If not, you could write an LSM that prohibits unlinking
/dev/stderr.Jan Engelhardt
That symlink isn't even used -- at least by any sane program! I don't have a clue why these things were created and what they were for. The objects stdin, stdout, and stderr, are 'C' runtime library pointers to opaque types associated with the file descriptors, STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO. The presence of these bogus sym-links in /dev represent some kind of obfuscation and have no value except to confuse (or identify a RedHat distribution).
Cheers,
Dick Johnson
Penguin : Linux version 2.6.15.4 on an i686 machine (5589.54 BogoMips). Warning : 98.36% of all statistics are fiction, book release in April. _
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
Quoted 6 lines · Stefan Seyfried
Quoted 2 lines · Denis Vlasenko
Mysql people are strange. For example, their daemon does not want to die on SIGTERM, this makes it harder to run it under daemontools.
Well, daemontools are equally strange ;-))
IMHO the most sane way to control zillions of background processes.
Quoted 20 lines
Quoted 20 lines
Also it drops privileges BEFORE it opens logfiles (--log=xxx). I cannot get it to log stuff on stderr:
echo "* Starting mysqld"
env - \
setuidgid root \mysqld \ --defaults-file="$PWD/my.cnf" \ --user="$user" \ --datadir="$var/data" \ --tmpdir="$var/tmp" \ --socket="$PWD/mysql.socket" \ --pid-file="$PWD/mysql.pid" \ --skip-name-resolve \ --skip-innodb \ --skip-ndbcluster \ --skip-networking \ --log=/proc/self/fd/2 \ --log-slow-queries=/proc/self/fd/2 \
Quoted 6 lines
Quoted 3 lines
Those last two options don't work:
mysqld: File '
/proc/self/fd/2' not found (Errcode: 13)any good daemon closes stdout, stderr, stdin and does chdir(/) on startup. msqld might do so as well.
No. Good daemon (e.g. apache does it) will open log file first, and _then_ will do setuid($user). Mysql tries to do it in opposite order, and (no wonder) fails to open the log.
--
vda