I am trying to make a fake GPS device so that I can put the wrong time in the output, and then make sure that when I set up chrony and gpsd, I am getting the time from serial feed that I set up. If I use the real gps output, I won't really know if I am still getting the time from NTP.

What I have tried:

I followed this: https://stackoverflow.com/questions/52187/virtual-serial-port-for-linux

socat -d -d pty,raw,echo=0 pty,raw,echo=0

then I tried to pipe in a new modified feed like this:

cat /dev/ttyUSB0 | sed 's/11/15/g' > /dev/pts/5

(since it is currently 11:?? UTC, that should change the time)

and when I look at the output like this cat /dev/pts/6 it looks like it should. (the same as cat /dev/ttyUSB0 but with the replacement)

so now try to connect to it:

gpsd -D 5 -N -n /dev/pts/10

I get bad news:

$ sudo gpsd -D 5 -N -n /dev/pts/6
gpsd:INFO: launching (Version 3.22)
gpsd:IO: opening IPv4 socket
gpsd:IO: opening IPv6 socket
gpsd:INFO: listening on port gpsd
gpsd:PROG: NTP: shmat(15,0,0) succeeded, segment 0
gpsd:PROG: NTP: shmat(16,0,0) succeeded, segment 1
gpsd:PROG: NTP: shmat(17,0,0) succeeded, segment 2
gpsd:PROG: NTP: shmat(18,0,0) succeeded, segment 3
gpsd:PROG: NTP: shmat(19,0,0) succeeded, segment 4
gpsd:PROG: NTP: shmat(20,0,0) succeeded, segment 5
gpsd:PROG: NTP: shmat(21,0,0) succeeded, segment 6
gpsd:PROG: NTP: shmat(22,0,0) succeeded, segment 7
gpsd:PROG: successfully connected to the DBUS system bus
gpsd:PROG: shmget(0x47505344, 24512, 0666) for SHM export succeeded
gpsd:PROG: shmat() for SHM export succeeded, segment 23
gpsd:INFO: stashing device /dev/pts/6 at slot 0
gpsd:PROG: no /etc/gpsd/device-hook present, skipped running ACTIVATE hook
gpsd:INFO: SER: opening GPS data source type 6 at '/dev/pts/6'
gpsd:ERROR: SER: device open of /dev/pts/6 failed: Permission denied - retrying read-only
gpsd:ERROR: SER: read-only device open of /dev/pts/6 failed: Permission denied
gpsd:ERROR: initial GPS device /dev/pts/6 open failed
gpsd:ERROR: can't run with neither control socket nor devices open

I 777ed /dev/pts/5 and /dev/pts/6 in case.

Is this really a permission issue? or is my fake GPS not a good enough fake?

Note: I'll take any advice I can get:

  • a better way make sure you are getting time from gps
  • a better way to make a fake gps device
  • what I am doing wrong with the fake GPS above

responding to a comment, I think these are the relevant strace lines:

openat(AT_FDCWD, "/dev/pts/9", O_RDWR|O_NOCTTY|O_NONBLOCK) = -1 EACCES (Permission denied)                                                                                                                         
openat(AT_FDCWD, "/dev/pts/9", O_RDONLY|O_NOCTTY|O_NONBLOCK) = -1 EACCES (Permission denied)

one is the original try, and then the second is retrying with readonly I am running gpsd as root btw sudo strace /usr/sbin/gpsd -D 5 -N -n /dev/pts/9

(the /dev/pts # changes every time I set this up - so sorry they aren't all consistent)

  • Do you have SE-Linux or AppArmor enforcing? If not, start gpsd under strace to see which system calls it uses Feb 5 at 20:43


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.