programe start by systemctl can not mount device

Issues related to applications and software problems
Post Reply
liu.jicheng
Posts: 1
Joined: 2018/06/14 03:36:51

programe start by systemctl can not mount device

Post by liu.jicheng » 2018/06/14 03:49:28

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?

tunk
Posts: 1205
Joined: 2017/02/22 15:08:17

Re: programe start by systemctl can not mount device

Post by tunk » 2018/06/14 09:54:05

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.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: programe start by systemctl can not mount device

Post by TrevorH » 2018/06/14 10:10:56

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

Post Reply