the follow is my code:
#include <sys/mount.h>
#include <unistd.h>
#include <stdio.h>
using namespace std;
int main()
{
printf("start to mount ****** \n");
int ret;
ret = mount("/dev/sdc", "/mnt/test", "ext4", 0, NULL);
if(ret != 0) {
printf("mount failed\n");
throw;
}else {
printf("mount successful");
}
sleep(1000000);
}
I use g++ test.cc -o mount-test -g to create program file "mount-test".
I execute mount-test by terminal window, the program can mount device /dev/sdc successful.
but , if I use systemctl to execute the mount-test, use command "systectl start mount-test" it can not mount /dev/sdc to dirctory /mnt/test, and the mount function will not report error.
[root@localhost system]# cat mount-test.service
[Unit]
Description=mount test service
After=network.target
[Service]
ExecStart=/root/mount-test
PrivateTmp=true
[Install]
WantedBy=multi-user.target
why the porgram start by systemd can not mount successful?
programe start by systemctl can not mount device
-
- Posts: 1
- Joined: 2018/06/14 03:36:51
Re: programe start by systemctl can not mount device
I don't know if it will work, but you could try to add User=root under [Service].
You may also want to log printf output to a file, e.g. /tmp/mount-test.log.
You may also want to log printf output to a file, e.g. /tmp/mount-test.log.
Re: programe start by systemctl can not mount device
Got any entries in the output from aureport -a timestamped around the time of your last attempt?
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke