# Trying to port LXDM



## AntumDeluge (Aug 26, 2014)

*Note:* I have also posted this to the LXDE forums: http://forum.lxde.org/viewtopic.php?f=1&t=36839

So far with some help from the users of #bsdports on the EFNet IRC channel, I have been able to compile LXDM. But, I am now having problems linking. I will name some of the fixes that I have used (some are ugly hacks):

*Error 1:*

```
WARNING: sysconfdir is not /etc.
```

*Solution 1:*

Set --sysconfdir flag to /usr/local/etc: `./configure --sysconfdir=$PREFIX/etc`.

*Error 2:*

```
invalid application of 'sizeof' to incomplete type 'LXDM_CRED'
```

*Solution 2:*

Define _WANT_UCRED in src/lxcom.h or src/lxcom.c before the sys/ucred.h is included.

Include sys/param.h in src/lxcom.h and change all defined(__NetBSD__) except the first one to defined(BSD) in src/lxcom.c:

src/lxcom.h:

```
#ifndef _LXCOM_H_
  #define LXCOM_H_

+ #if defined(__unix__) || defined(unix)
+ #include <sys/param.h>
+ #endif
+
+ #if !defined(_WANT_UCRED)
+   #define _WANT_UCRED
+ #endif

void lxcom_init(const char *sock);
...
```
src/lxcom.c:

```
#endif

- #if defined(__NetBSD__)
+ #if defined(BSD)
  typedef struct sockcred LXDM_CRED;
```

*Error 3:*


```
src/lxcom.c:147:11: error: 'cred' undeclared (first use in this function)
```
*Solution 3:*

Replace cred * with struct sockcred for FreeBSD in src/lxcom.c:

src/lxcom.c:

```
...
+ #if defined(__FreeBSD__)
+ size = SOCKCREDSIZE(((struct sockcred *)CMSG_DATA(cmptr))->sc_ngroups);
+ #else
  size = SOCKCREDSIZE(((cred *)CMSG_DATA(cmptr))->sc_ngroups);
+ #endif /* __FreeBSD__ */
...
```

*Error 4:*


```
src/lxcom.c:158:71: error: called object '1' is not a function
```

*Solution 4:*

Remove the (c) from LXDM_PEER_PID for FreeBSD in src/lxcom.c:

src/lxcom.c:

```
...
+ #if defined(__FreeBSD__)
+ res=((LXComFunc)callback)(user_data,LXDM_PEER_UID(c),LXDM_PEER_PID,argc,argv);
+ #else
  res=((LXComFunc)callback)(user_data,LXDM_PEER_UID(c),LXDM_PEER_PID(c),argc,argv);
+ #endif /* __FreeBSD__ */
...
```

*Error 5:*


```
src/lxcom.c:294:43: error: 'SO_PASSCRED' undeclared (first use in this function)
```

*Solution 5:* HACK

Define SO_PASSCRED as 16 (for i386 and amd64, it may need to be different for other platforms) in src/lxcom.h.

src/lxcom.h:

```
...
  #endif

+ #if !defined(SO_PASSCRED)
+   #define SO_PASSCRED 16
+ #endif

  void lxcom_init(const char *sock);
...
```

*Error 6:*


```
src/pam.c:48:20: fatal error: shadow.h: No such file or directory
compilation terminated.
```

*Solution 6:*

Include xorg/shadow.h for FreeBSD in src/pam.c, src/lxdm.c and src/auth.c.

src/pam.c:

```
...
  #include <grp.h>

+ #if defined(__FreeBSD__)
+ #include <xorg/shadow.h>
+ #else
  #include <shadow.h>
+ #endif

  #include <glib.h>
...
```

*Error 7:*


```
/usr/local/include/xorg/miscstruct.h:53:20: fatal error: pixman.h: No such file or directory
```

*Solution 7:* HACK

Add an include to the pixman-1 directory.


```
$ make CFLAGS="-I/usr/local/include/pixman-1"
```

*Error 8:*


```
src/lxdm.c:54:20: fatal error: sys/vt.h: No such file or directory
```

*Solution 8:* HACK

Remove the include of sys/vt.h from src/lxdm.c for FreeBSD and create a new struct and two new defines in src/lxdm.h.

src/lxdm.c:

```
...
#include <glib/gstdio.h>

#if !defined(__FreeBSD__)
#include <sys/vt.h>
#endif

#include <sys/ioctl.h>
...
```

src/lxdm.h:

```
...
void free_xsessions(GSList *);

struct vt_stat {
	unsigned short v_active;	/* active vt */
	unsigned short v_signal;	/* signal to send */
	unsigned short v_state;		/* vt bitmask */
};

#define VT_GETSTATE	0x5603
#define VT_ACTIVATE	0x5606

G_END_DECLS
...
```

*Linker errors:*

Those solutions fixed the compile errors. But now I am left with a load of linker errors:

```
lxdm_binary-lxdm.o: In function `lxsession_stop':
lxdm.c:(.text+0x7d0): undefined reference to `xconn_clean'
lxdm_binary-lxdm.o: In function `lxsession_free':
lxdm.c:(.text+0x8c8): undefined reference to `xconn_close'
lxdm_binary-lxdm.o: In function `on_xserver_stop':
lxdm.c:(.text+0x1be8): undefined reference to `xconn_close'
lxdm_binary-lxdm.o: In function `lxdm_startx':
lxdm.c:(.text+0x1dbe): undefined reference to `xconn_open'
lxdm_binary-lxdm.o: In function `log_sigsegv':
lxdm.c:(.text+0x3386): undefined reference to `backtrace'
lxdm.c:(.text+0x33a0): undefined reference to `backtrace_symbols'
collect2: error: ld returned 1 exit status
```
[/file]


----------



## JX8P (Aug 26, 2014)

Try linking with the extra flags -lexecinfo to deal with the references to backtrace and backtrace_symbols.

This will link with the libexecinfo library which contains those functions.


----------



## olivierd (Aug 26, 2014)

Some functions in Lxdm read also /proc, be careful.


----------



## AntumDeluge (Aug 26, 2014)

olivierd said:
			
		

> Some functions in Lxdm read also /proc, be careful.



I don't know much about the /proc system. That handles working processes, correct?


----------



## JX8P (Aug 26, 2014)

AntumDeluge said:
			
		

> JX8P said:
> 
> 
> 
> ...



It seems like those are internal functions. Take a look in src/xconn.c to check if there's any reason why they aren't being found. Googling suggests that they may be wrapped in 
	
	



```
#if 0
#endif
```
Remove those and see what happens.


----------



## AntumDeluge (Aug 27, 2014)

I removed the #if 0's but am still getting _the_ same error.

src/xconn.c:

```
free(c);
  }

- #if 0
  static xcb_window_t xconn_get_root(xconn_t c)
  {
      const xcb_setup_t *setup;
      setup=xcb_get_setup(c->c);
      xcb_screen_iterator_t iter = xcb_setup_roots_iterator (setup);
      xcb_screen_t *screen = iter.data;
      return screen->root;
  }
- #endif

  void xconn_clean(xconn_t c)
  {
- #if 0
      xcb_query_tree_cookie_t wintree;
      xcb_query_tree_reply_t *rep;
      xcb_window_t *children;
      xcb_window_t root;
      int i,len;
      if(!c) return;
      root=xconn_get_root(c);
      wintree = xcb_query_tree(c->c, root);
      rep = xcb_query_tree_reply(c->c, wintree, 0);
      if(!rep) return;
      len = xcb_query_tree_children_length(rep);
      children = xcb_query_tree_children(rep);
      for(i=0;i<len;i++)
          xcb_kill_client(c->c,children[i]);
      free(rep);
      xcb_flush(c->c);
- #endif
  }[/i]
```
_

*Edit:* I tried adding -DLXDM_XCONN_XCB to the make command but the same problem persists._


----------



## JX8P (Aug 28, 2014)

AntumDeluge said:
			
		

> Removed the #if 0's but still getting same error.
> 
> src/xconn.c:
> 
> ...



I would suggest trying to add -DLXDM_XCONN_XLIB, making to run `make clean` first. You will probably also need to add -L/usr/local/lib -lX11 since the functions that would activate appear to use libX11.


----------



## AntumDeluge (Aug 28, 2014)

Problems persist.


----------



## AntumDeluge (Aug 28, 2014)

This is the gcc command where the linking error is occurring:

```
gcc -I/usr/local/include/glib-2.0 -I/usr/local/include  -DCONFIG_FILE=\"/etc/lxdm/lxdm.conf\"  -DXSESSIONS_DIR=\"/usr/local/share/xsessions\"  -DLXDM_DATA_DIR=/usr/local/share/lxdm  -DLXDM_NUMLOCK_PATH=\"/usr/local/libexec/lxdm-numlock\"  -DLXDM_SESSION_PATH=\"/usr/local/libexec/lxdm-session\"  -I/usr/local/include/ConsoleKit/ck-connector -I/usr/local/include/dbus-1.0 -I/usr/local/include/dbus-1.0/include  -Werror-implicit-function-declaration  -Wall   -I/usr/local/include/pixman-1   -lexecinfo -o lxdm-binary lxdm_binary-lxdm.o  lxdm_binary-ui.o lxdm_binary-lxcom.o  lxdm_binary-xconn.o lxdm_binary-auth.o   -L/usr/local/lib -lglib-2.0 -lintl  -L/usr/local/lib -lxcb  -lck-connector -L/usr/local/lib -ldbus-1   -lck-connector -lpam -lcrypt
lxdm_binary-lxdm.o: In function `lxsession_stop':
lxdm.c:(.text+0x7d0): undefined reference to `xconn_clean'
lxdm_binary-lxdm.o: In function `lxsession_free':
lxdm.c:(.text+0x8c8): undefined reference to `xconn_close'
lxdm_binary-lxdm.o: In function `on_xserver_stop':
lxdm.c:(.text+0x1be8): undefined reference to `xconn_close'
lxdm_binary-lxdm.o: In function `lxdm_startx':
lxdm.c:(.text+0x1dbe): undefined reference to `xconn_open'
collect2: error: ld returned 1 exit status
*** Error code 1
```

The error occurs when trying to build the executable lxdm-binary. The xconn_close(), xconn_clean() and xconn_open() functions are defined in the created object file src/lxdm_binary-lxdm.o, which appears to be included in the command:

```
$ grep -r "xconn_close" ./
Binary file ./src/lxdm_binary-lxdm.o matches
```


----------



## Amzo (Oct 6, 2014)

I continued where you left off, and the only undefined references I got were:

```
lxdm.c:(.text+0xae9): undefined reference to `xstrcasecmp'
lxdm.c:(.text+0xafe): undefined reference to `xstrcasecmp'
lxdm.c:(.text+0xb13): undefined reference to `xstrcasecmp'
lxdm.c:(.text+0xb28): undefined reference to `xstrcasecmp'
lxdm.c:(.text+0xb3d): undefined reference to `xstrcasecmp'
```

I worked around those and it linked and runs after. Of course it's missing an initialisation file for startup, but I need to fix some minor issues: the keyboard doesn't work, shutdown and reboot aren't working, and some permission denied errors. 

I'm unsure why you're getting those undefined references, so maybe you can post some additional steps you took. And for a note that may help, I used the system's ltmain.sh instead of the provided one.

LXDM log:

```
** Message: find greeter 0x0

** Message: find idle 0x0

** Message: 1412569007: add xserver watch


X.Org X Server 1.16.0
Release Date: 2014-07-16
X Protocol Version 11, Revision 0
Build Operating System: FreeBSD 10.0-STABLE x86_64 
Current Operating System: FreeBSD Bahamut 10.1-BETA3 FreeBSD 10.1-BETA3 #0 37636a7bdce0c74975e45d664648e04ee6b0e6b0(makepkg): Mon Sep 29 18:12:18 UTC 2014     root@Bahamut x86_64
Build Date: 23 September 2014  03:06:43PM
 
Current version of pixman: 0.32.6
	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
	(++) from command line, (!!) notice, (II) informational,
	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Mon Oct  6 04:16:47 2014
(==) Using config file: "/etc/X11/xorg.conf"
(==) Using config directory: "/etc/X11/xorg.conf.d"
** Message: 1412569008: start xserver in 1 retry
** Message: add 0x805852180

** Message: prepare greeter on :0

** Message: start greeter on :0

bind: Permission denied
** Message: USER_LIST fail

** Message: quit code 0

** Message: exit cb

shutdown: [pid 68925]
Shutdown NOW!
Shutdown NOW!

System shutdown time has arrived
(EE) Server terminated successfully (0). Closing log file.
** Message: free session
```

I'll continue and fix what I can and post my finished patches.

I'd just like to note that there are a lot of hard coded paths to /usr:

```
src/lxdm-0.5.0/src/lang.c:#define LXDM_DATA_DIR   "/usr/share/lxdm"
src/lxdm-0.5.0/src/lxdm.c:	if(!p) p=g_strdup("/usr/bin/X");	
src/lxdm-0.5.0/src/lxdm.c:	if( !s ) s = g_strdup("/usr/bin/X");
src/lxdm-0.5.0/src/lxdm.c:		env=g_environ_setenv(env, "PATH", "/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin", TRUE); /* set proper default */
src/lxdm-0.5.0/src/greeter.c:#define XKB_SYMBOL_DIR		"/usr/share/X11/xkb/symbols.dir"
src/lxdm-0.5.0/src/greeter.c:	dir=g_dir_open("/usr/share/X11/xkb/symbols",0,FALSE);
src/lxdm-0.5.0/src/greeter.c:    bindtextdomain("lxdm", "/usr/share/locale");
src/lxdm-0.5.0/src/config.c:#define FACES_DIR			"/usr/share/pixmaps/faces"
src/lxdm-0.5.0/src/config.c:	bindtextdomain("lxdm", "/usr/share/locale");
```

UPDATE:

The keyboard is working, as are the shutdown/reboot menu commands. It doesn't get a user list yet, and doesn't login to a session.


----------



## AntumDeluge (Oct 7, 2014)

Thanks for the info Amzo. I'll try again when I get some time and post what I come up with. I'd like to be able to send patches upstream as well so that hopefully the LXDE developers will start supporting BSD/FreeBSD.


----------



## Amzo (Oct 7, 2014)

I got further today, and found some more issues.

The last linking issue with undefined symbols to xstrcasecmp was caused because /usr/local/include/xorg/os.h has a check for strcasecmp. If it wasn't defined it would be set to xstrcasecmp.

Well, `configure` for LXDM detected strcasecmp, but it wasn't being defined, so I ended up with undefined references to xstrcasecmp. That was fixed by passing -DHAVE_STRCASECMP to CFLAGS.

Well, there are still a  few problems which prevent it from working correctly.


Userlist: Doesn't Get the Userlist.
Session: Doesn't get the Sessionlist.
Locale: Doesn't get the list of locales.

But so far things seem to be fine. What is fixed and working:


 Shutdown: patched command to `shutdown -p now`.
Reboot: patched command to `shutdown -r now`.
Proc: Use linprocfs and patch paths to /compat/linux/prc.


----------



## Chris_H (Nov 5, 2014)

FWIW you should be able to get around the locale(5) issue by defining it in ~/.xsession.

--Chris


----------

