Setting device permission from driver code fails - linux-device-driver

I want to access I2C device driver nodes from user space in a linux kernel 3.10.14.
I added i2c-dev in the kernel configuration and got the /dev/i2c-* device nodes. However they have permission
$ ls -l /dev/i2c-*
crw------- root root 89, 1 2014-08-21 20:00 i2c-1
In drivers/i2c/i2c-dev.c I added the callback
static char *i2c_dev_devnode(struct device *dev, umode_t *mode)
{
if (!mode)
return NULL;
if (MAJOR(dev->devt) == I2C_MAJOR)
*mode = 0666;
return NULL;
}
and in the same file I added the callback to the device class struct:
static int __init i2c_dev_init(void)
{
...
i2c_dev_class = class_create(THIS_MODULE, "i2c-dev");
...
/* set access rights */
i2c_dev_class->devnode = i2c_dev_devnode;
...
}
However the access rights of the device node remain
crw------- root root 89, 1 2014-08-21 20:00 i2c-1
There is no /lib/udev/rules.d or /etc/udev/rules.d
I would appreciate any suggestions what might go wrong here.
I am also interested in ideas how to test this issue.

You might try the following. This works at least with kernel 4.9.56.
static int my_uevent(struct device *dev, struct kobj_uevent_env *env)
{
add_uevent_var(env, "DEVMODE=%#o", 0666);
return 0;
}
static int __init i2c_dev_init(void)
{
...
i2c_dev_class = class_create(THIS_MODULE, "i2c-dev");
...
/* set access rights */
i2c_dev_class->dev_uevent = my_uevent;
...
}

I understand the return value of devnode callback function shall not be "NULL" but device node name.
So,
Change your functions return value from "NULL" to devname. Refer the code:
----------------------patch--------------------
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 6f638bb..35a42c6 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
## -614,6 +614,14 ## static int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action,
.notifier_call = i2cdev_notifier_call,
};
+static char *i2c_dev_devnode(struct device *dev, umode_t *mode)
+{
+ printk("\n\n****%s: %d\n\n",__func__,__LINE__);
+ if (mode != NULL)
+ *mode = 0666;
+ return kasprintf(GFP_KERNEL, "i2cr/%s", dev_name(dev));;
+}
+
/* ------------------------------------------------------------------------- */
/*
## -636,7 +644,12 ## static int __init i2c_dev_init(void)
goto out_unreg_chrdev;
}
i2c_dev_class->dev_groups = i2c_groups;
+ /* set access rights */
+ printk(KERN_INFO "i2c setting devnode\n");
+ i2c_dev_class->devnode = i2c_dev_devnode;
+
+
/* Keep track of adapters which will be added or removed later */
res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
if (res)
Results:
Without applying this patch:
root#x86-generic-64:~# ls -l /dev/i2c-*
crw------- 1 root root 89, 0 Nov 1 13:47 /dev/i2c-0
crw------- 1 root root 89, 1 Nov 1 13:47 /dev/i2c-1
With patch:
root#x86-generic-64:~# ls -l /dev/i2cr/*
crw-rw-rw- 1 root root 89, 0 Nov 1 13:38 /dev/i2cr/i2c-0
crw-rw-rw- 1 root root 89, 1 Nov 1 13:38 /dev/i2cr/i2c-1

Setting up device node is responsibility of udev. So we need to use correct udev rule. Further init.rc approach will fail if driver is loaded after boot time for example in case it is a loadable module. Your distribution might be using another way of supporting hotplug so we need to consult documentation about that distro.

Related

VxWorks 653 Restart after START command

Using VxWorks 653 2.5.0.2 for P2020RDB-PC target, using BSP1.0/4
I have a very simple test application
void usrAppInit (void)
{
RETURN_CODE_TYPE errCode;
printf("\n I am alive!");
PROCESS_ATTRIBUTE_TYPE processAttributes;
PROCESS_ID_TYPE thandle;
processAttributes.BASE_PRIORITY = 10;
processAttributes.DEADLINE = SOFT;
processAttributes.ENTRY_POINT = (SYSTEM_ADDRESS_TYPE)task;
strncpy(processAttributes.NAME, "TASK", MAX_NAME_LENGTH);
processAttributes.PERIOD = INFINITE_TIME_VALUE;
processAttributes.STACK_SIZE = 1024;
processAttributes.TIME_CAPACITY = INFINITE_TIME_VALUE;
CREATE_PROCESS(&processAttributes, &thandle, &errCode);
if(errCode != NO_ERROR)
{
printf("Just had an error creating the task: %d", errCode);
}
else
{
START(thandle, &errCode);
if(errCode != NO_ERROR)
{
printf("Just had an error starting the task: %d", errCode);
}
}
SET_PARTITION_MODE (NORMAL, &errCode);
if (errCode != NO_ERROR){
printf("\nError changing partition mode: %d", errCode);
}
while(1);
}
void task()
{
printf("\nI am a process.");
while(1);
}
When the program gets to the START line, it reboots. If I comment out the START line, it executes till the end of the main and obviously does nothing. I have tried to increase partition memory and I am adding the APEX components to the makefile.
What could be causing this?
PS: system output
VxWorks 653 System Boot
Copyright (c) 1984-2016 Wind River Systems, Inc.
CPU: Freescale P2020E - Security Engine
Version: 2.5.0.2
BSP version: 1.0/4
Creation date: Apr 29 2020, 15:00:10
Press any key to stop auto-boot...
0
auto-booting...
boot device : mottsec
unit number : 0
processor number : 0
host name : felipe
file name : D:\Projects\WindRiver\helloWorld\boot.txt
inet on ethernet (e) : 192.168.1.172
host inet (h) : 192.168.1.75
gateway inet (g) : 192.168.1.1
user (u) : felipe
ftp password (pw) : pass
flags (f) : 0x0
target name (tn) : board
Attached TCP/IP interface to mottsec0.
Warning: netmask value is 0.
Attaching interface lo0...done
Loading D:\Projects\WindRiver\helloWorld\boot.txt
sm0=D:\Projects\WindRiver\helloWorld\configRecord.reloc
0x00001a00 + (0x000fe600)
sm1=D:\Projects\WindRiver\helloWorld\coreOS.sm
0x00050e08 + 0x00007130 + 0x00006084 + 0x00015cac
sm2=D:\Projects\WindRiver\helloWorld\vxSysLib.sm
0x00031078 + 0x00004b20 + 0x00000918 + 0x00001d90
sm3=D:\Projects\WindRiver\helloWorld\fsl_p2020_rdb_part1.sm
0x000027c8 + 0x000000d0 + 0x00000010 + 0x00000008
Starting at 0x100000...
After this, it returns to the beggining and repeats the process forever
So, in case anyone else drops here with similar issue, in my case there were two main things affecting the functionality.
First, in the usrAppInit() function, one cannot define the while(1) loop in the end of the function. On opposite to other ARINC-653 systems, where the partition main is the same as the user main, for VxWorks it does not seems to be the case. This way, after SET_PARTITION_MODE, nothing else can be defined.
Second, the stack size for the process was too small. That fit perfectly for different targets and ARINC RTOS (in-house OS, executing on ARMv7 target), but for VxWorks on the P2020 target it requires a bigger stack. In this case, I've used 4096.
Here is the complete example code, now functional, in case anyone needs this.
void usrAppInit (void)
{
RETURN_CODE_TYPE errCode;
printf("\n I am alive!");
PROCESS_ATTRIBUTE_TYPE processAttributes;
PROCESS_ID_TYPE thandle;
processAttributes.BASE_PRIORITY = 10;
processAttributes.DEADLINE = SOFT;
processAttributes.ENTRY_POINT = (SYSTEM_ADDRESS_TYPE)task;
strncpy(processAttributes.NAME, "TASK", MAX_NAME_LENGTH);
processAttributes.PERIOD = INFINITE_TIME_VALUE;
processAttributes.STACK_SIZE = 4096;
processAttributes.TIME_CAPACITY = INFINITE_TIME_VALUE;
CREATE_PROCESS(&processAttributes, &thandle, &errCode);
if(errCode != NO_ERROR)
{
printf("Just had an error creating the task: %d", errCode);
}
else
{
START(thandle, &errCode);
if(errCode != NO_ERROR)
{
printf("Just had an error starting the task: %d", errCode);
}
}
SET_PARTITION_MODE (NORMAL, &errCode);
if (errCode != NO_ERROR){
printf("\nError changing partition mode: %d", errCode);
}
}
void task()
{
printf("\nI am a process.");
while(1);
}

For Linux 3.10 what what changes do I need to make to get netmap/virtio_net working?

The netmap/virtio_net driver didn't work (Linux 3.10 kernel). There were two problems.
On the 3.10.60 kernel from kernel.org, the patch to virtio_net.c didn't
work, one part of the patch was rejected. This is easily fixed.
More serious, was that the virtio initialization code didn't work, nor
did the packet receive code. The basic problem was failure to initialize
the indices properly and failure to maintain a 1 slot separation between
head/tail indices. (Same problem 2 locations in the code.)
This problem is easily seen by creating a KVM guest with a
netmap/virtio_net driver, and simply pinging the guest from the host.
The receive traffic can easily be monitored using the pkt-gen tool on
the guest.
The first 255 pings will work fine, when the index hits 255, then the
packet receive will fail, and will continue to fail every time on slot 255.
I've included patches for both problems in the hopes that the source code
will be updated and others won't have to find these problems.
First virtio_netmap_3.10.60.patch:
# patch is the whole netmap virtio driver patch for 3.10.60 (from
# kernel.org), and it applies correctly.
#
Index: linux-3.10.60/drivers/net/virtio_net.c
===================================================================
--- linux-3.10.60.orig/drivers/net/virtio_net.c 2014-11-14 11:48:23.000000000 -0500
+++ linux-3.10.60/drivers/net/virtio_net.c 2014-11-21 12:54:29.751760095 -0500
## -131,6 +131,10 ##
struct notifier_block nb;
};
+#if defined(CONFIG_NETMAP) || defined(CONFIG_NETMAP_MODULE)
+#include <virtio_netmap.h>
+#endif
+
struct skb_vnet_hdr {
union {
struct virtio_net_hdr hdr;
## -210,6 +214,10 ##
/* Suppress further interrupts. */
virtqueue_disable_cb(vq);
+#ifdef DEV_NETMAP
+ if (netmap_tx_irq(vi->dev, vq2txq(vq)))
+ return;
+#endif
/* We were probably waiting for more output buffers. */
netif_wake_subqueue(vi->dev, vq2txq(vq));
}
## -646,7 +654,16 ##
struct virtnet_info *vi = rq->vq->vdev->priv;
void *buf;
unsigned int r, len, received = 0;
+#ifdef DEV_NETMAP
+ int work_done = 0;
+
+ if (netmap_rx_irq(vi->dev, vq2rxq(rq->vq), &work_done)) {
+ napi_complete(napi);
+ ND("called netmap_rx_irq");
+ return 1;
+ }
+#endif
again:
while (received < budget &&
(buf = virtqueue_get_buf(rq->vq, &len)) != NULL) {
## -679,6 +696,16 ##
{
struct virtnet_info *vi = netdev_priv(dev);
int i;
+#ifdef DEV_NETMAP
+ int ok = virtio_netmap_init_buffers(vi);
+
+ netmap_enable_all_rings(dev);
+ if (ok) {
+ for (i = 0; i < vi->max_queue_pairs; i++)
+ virtnet_napi_enable(&vi->rq[i]);
+ return 0;
+ }
+#endif
for (i = 0; i < vi->max_queue_pairs; i++) {
if (i < vi->curr_queue_pairs)
## -972,6 +999,9 ##
struct virtnet_info *vi = netdev_priv(dev);
int i;
+#ifdef DEV_NETMAP
+ netmap_disable_all_rings(dev);
+#endif
/* Make sure refill_work doesn't re-enable napi! */
cancel_delayed_work_sync(&vi->refill);
## -1644,6 +1674,10 ##
goto free_recv_bufs;
}
+#ifdef DEV_NETMAP
+ virtio_netmap_attach(vi);
+#endif
+
/* Assume link up if device can't report link status,
otherwise get link status from config. */
if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) {
## -1690,6 +1724,9 ##
{
struct virtnet_info *vi = vdev->priv;
+#ifdef DEV_NETMAP
+ netmap_detach(vi->dev);
+#endif
unregister_hotcpu_notifier(&vi->nb);
/* Prevent config work handler from accessing the device. */
Next is the virtio_netmap.patch
# There is a problem with the initialization, and during read packet with
# control of the indices .
#
# This problem is easily seen by building a KVM netmap/virtio_net driver, and
# simply pinging it (host pings KVM guest). All goes well, until ring buffer
# reaches index 255, and no packet is actually received. This will fix that
# problem and resulted in a working driver.
#
Index: b/LINUX/virtio_netmap.h
===================================================================
--- a/LINUX/virtio_netmap.h 2014-11-21 16:26:03.951278021 -0500
+++ b/LINUX/virtio_netmap.h 2014-11-21 16:26:25.451386665 -0500
## -398,8 +398,8 ##
* Second part: skip past packets that userspace has released.
*/
nm_i = kring->nr_hwcur; /* netmap ring index */
- if (nm_i != head) {
- for (n = 0; nm_i != head; n++) {
+ if (nm_next(nm_i, lim) != head) {
+ for (n = 0; nm_next(nm_i, lim) != head; n++) {
struct netmap_slot *slot = &ring->slot[nm_i];
void *addr = NMB(slot);
int err;
## -421,7 +421,7 ##
virtqueue_kick(vq);
nm_i = nm_next(nm_i, lim);
}
- kring->nr_hwcur = head;
+ kring->nr_hwcur = nm_i;
}
/* We have finished processing used RX buffers, so we have to tell
## -454,6 +454,7 ##
for (r = 0; r < na->num_rx_rings; r++) {
COMPAT_DECL_SG
struct netmap_ring *ring = na->rx_rings[r].ring;
+ struct netmap_kring *kring = &na->rx_rings[r];
struct virtqueue *vq = GET_RX_VQ(vi, r);
struct scatterlist *sg = GET_RX_SG(vi, r);
struct netmap_slot* slot;
## -485,6 +486,7 ##
if (VQ_FULL(vq, err))
break;
}
+ kring->nr_hwcur = i;
D("added %d inbufs on queue %d", i, r);
virtqueue_kick(vq);
}

500 internal server error on certain page after a few hours

I am getting a 500 Internal Server Error on a certain page of my site after a few hours of being up. I restart uWSGI instance with uwsgi --ini /home/metheuser/webapps/ers_portal/ers_portal_uwsgi.ini and it works again for a few hours.
The rest of the site seems to be working. When I navigate to my_table, I am directed to the login page. But, I get the 500 error on my table page on login. I followed the instructions here to set up my nginx and uwsgi configs.
That is, I have ers_portal_nginx.conf located i my app folder that is symlinked to /etc/nginx/conf.d/. I start my uWSGI "instance" (not sure what exactly to call it) in a Screen instance as mentioned above, with the .ini file located in my app folder
My ers_portal_nginx.conf:
server {
listen 80;
server_name www.mydomain.com;
location / { try_files $uri #app; }
location #app {
include uwsgi_params;
uwsgi_pass unix:/home/metheuser/webapps/ers_portal/run_web_uwsgi.sock;
}
}
My ers_portal_uwsgi.ini:
[uwsgi]
#user info
uid = metheuser
gid = ers_group
#application's base folder
base = /home/metheuser/webapps/ers_portal
#python module to import
app = run_web
module = %(app)
home = %(base)/ers_portal_venv
pythonpath = %(base)
#socket file's location
socket = /home/metheuser/webapps/ers_portal/%n.sock
#permissions for the socket file
chmod-socket = 666
#uwsgi varible only, does not relate to your flask application
callable = app
#location of log files
logto = /home/metheuser/webapps/ers_portal/logs/%n.log
Relevant parts of my views.py
data_modification_time = None
data = None
def reload_data():
global data_modification_time, data, sites, column_names
filename = '/home/metheuser/webapps/ers_portal/app/static/' + ec.dd_filename
mtime = os.stat(filename).st_mtime
if data_modification_time != mtime:
data_modification_time = mtime
with open(filename) as f:
data = pickle.load(f)
return data
#a bunch of authentication stuff...
#app.route('/')
#app.route('/index')
def index():
return render_template("index.html",
title = 'Main',)
#app.route('/login', methods = ['GET', 'POST'])
def login():
login stuff...
#app.route('/my_table')
#login_required
def my_table():
print 'trying to access data table...'
data = reload_data()
return render_template("my_table.html",
title = "Rundata Viewer",
sts = sites,
cn = column_names,
data = data) # dictionary of data
I installed nginx via yum as described here (yesterday)
I am using uWSGI installed in my venv via pip
I am on CentOS 6
My uwsgi log shows:
Wed Jun 11 17:20:01 2014 - uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.c line 287] during GET /whm-server-status (127.0.0.1)
IOError: write error
[pid: 9586|app: 0|req: 135/135] 127.0.0.1 () {24 vars in 292 bytes} [Wed Jun 11 17:20:01 2014] GET /whm-server-status => generated 0 bytes in 3 msecs (HTTP/1.0 404) 2 headers in 0 bytes (0 switches on core 0)
When its working, the print statement in the views "my_table" route prints into the log file. But not once it stops working.
Any ideas?

How to build Qt 5.2 on Solaris 10?

The Qt page does not list pre-compiled Qt 5 packages for Solaris. Searching around, it does not seem to be included in the popular package repository OpenCSW, either. Some google hits suggest that building Qt 5 under Solaris involves some work under Solaris 10.
Thus my question: How to build Qt 5.2 under Solaris 10?
Basically it is:
cd qt-everywhere-opensource-src-5.2.0
./configure -prefix $MY_PREFIX -opensource -confirm-license -nomake tests \
-R /opt/csw/lib/64 -R /opt/csw/X11/lib/64 -qt-xcb -platform solaris-g++-64 \
-verbose
gmake -j16
gmake -j16 install
plus some adjustments because Qt 5 does not seem to be used on
Solaris much, yet.
Adjustments
Obtain the source
wget http://download.qt-project.org/official_releases/qt/5.2/5.2.0/single/qt-everywhere-opensource-src-5.2.0.tar.gz
md5sum qt-everywhere-opensource-src-5.2.0.tar.gz
228b6384dfd7272de00fd8b2c144fecd qt-everywhere-opensource-src-5.2.0.tar.gz
If the system does not habe md5sum you can use openssl md5 filename instead.
Install dependencies
I recommend to use OpenCSW because we need some dependencies to build Qt. The most important ones are:
CSWlibxcbdevel
CSWlibicu-dev # soft-dependency
CSWgcc4g++
CSWgmake
I suggest to use GCC to compile Qt. I am not aware of any advantages using the C++ compiler from Solaris Studio. On the contrary, the level of C++/STL support of this compiler may be not sufficient for a lot of use cases.
Setup environment
Make sure that you environment is clean. That means that /opt/csw/bin comes first and no LD_LIBRAYR_PATH* variables are set.
To simplify things it is probably a good idea that some directories are removed from PATH. For example such that no cc, CC commands from a Solaris Studio installation are accidentally picked up (e.g. during the compile of a bundled 3rd party component.
Adjust the specs
The software under /usr/sfw is just too outdated. /opt/csw from OpenCSW is a better replacement. Then the X-Open version is not sufficient for some used system functions.
--- a/qtbase/mkspecs/solaris-g++-64/qmake.conf
+++ b/qtbase/mkspecs/solaris-g++-64/qmake.conf
## -35,7 +35,7 ## QMAKE_LEX = flex
QMAKE_LEXFLAGS =
QMAKE_YACC = yacc
QMAKE_YACCFLAGS = -d
-QMAKE_CFLAGS = -m64 -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
+QMAKE_CFLAGS = -m64 -D_XOPEN_SOURCE=600 -D__EXTENSIONS__
QMAKE_CFLAGS_DEPS = -M
QMAKE_CFLAGS_WARN_ON = -Wall -W
QMAKE_CFLAGS_WARN_OFF = -w
## -58,8 +58,8 ## QMAKE_CXXFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_STATIC_LIB
QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD
-QMAKE_INCDIR = /usr/sfw/include
-QMAKE_LIBDIR = /usr/sfw/lib/64
+QMAKE_INCDIR = /opt/csw/include /opt/csw/X11/include
+QMAKE_LIBDIR = /opt/csw/lib/64 /opt/csw/X11/lib/64
QMAKE_INCDIR_X11 = /usr/openwin/include
QMAKE_LIBDIR_X11 = /usr/openwin/lib/64
QMAKE_INCDIR_OPENGL = /usr/openwin/include
Fix the shell
Solaris comes with a /bin/sh that violates POSIX to an extend such
that Qt's configure scripts and even shell-code in qmake-generated
code fails.
POSIX does not specify that /bin/sh has to be conforming it just specifies that the system must have a conforming shell available 'somewhere'. On Solaris it is e.g. under /usr/xpg4/bin/sh. The portable way to get a conforming shell is to search for it in the directories returned by getconf CS_PATH ...
Anyways, my choice for Solaris is to just use /usr/bin/bash:
Anyways, my choice for Solaris is to just use /usr/bin/bash:
--- a/configure
+++ b/configure
## -1,4 +1,4 ##
-#! /bin/sh
+#!/usr/bin/bash
#############################################################################
##
## Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
--- a/qtbase/configure
+++ b/qtbase/configure
## -1,4 +1,4 ##
-#!/bin/sh
+#!/usr/bin/bash
#############################################################################
##
## Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
## -6892,7 +6892,7 ## fi'`
echo "$CONFIG_STATUS" | grep '\-confirm\-license' >/dev/null 2>&1 || CONFIG_STATUS="$CONFIG_STATUS -confirm-license"
[ -f "$outpath/config.status" ] && rm -f "$outpath/config.status"
- echo "#!/bin/sh" > "$outpath/config.status"
+ echo "#!/usr/bin/bash" > "$outpath/config.status"
[ -n "$PKG_CONFIG_SYSROOT_DIR" ] && \
echo "export PKG_CONFIG_SYSROOT_DIR=$PKG_CONFIG_SYSROOT_DIR" >> "$outpath/config.status"
[ -n "$PKG_CONFIG_LIBDIR" ] && \
--- a/qtbase/qmake/generators/makefile.cpp
+++ b/qtbase/qmake/generators/makefile.cpp
## -2306,6 +2306,10 ## MakefileGenerator::writeHeader(QTextStream &t)
if (ofile.lastIndexOf(Option::dir_sep) != -1)
ofile.remove(0, ofile.lastIndexOf(Option::dir_sep) +1);
t << "MAKEFILE = " << ofile << endl << endl;
+
+ t << "# custom mod because Solaris /bin/sh is such a standard-violating choice\n"
+ << "# - gs, 2013-12-23" << endl;
+ t << "SHELL = /usr/bin/bash" << endl << endl;
}
QList<MakefileGenerator::SubTarget*>
Fix the ICU test
Solaris 10 comes with an outdated libicu - which is missing features Qt 5 needs. Thus, we simply extend the icu-test. Then either no ICU-support is build or proper one in case we install a recent libicu e.g. via OpenCSW.
--- a/qtbase/config.tests/unix/icu/icu.cpp
+++ b/qtbase/config.tests/unix/icu/icu.cpp
## -43,6 +43,16 ##
#include <unicode/ucol.h>
#include <unicode/ustring.h>
+// for testing if ucal_clone is there (i.e. if we have libicu >= 4.0)
+#include <unicode/ucal.h>
+
+static UCalendar *ucp(UCalendar *i)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ UCalendar *r = ucal_clone(i, &status);
+ return r;
+}
+
int main(int, char **)
{
UErrorCode status = U_ZERO_ERROR;
## -50,5 +60,10 ## int main(int, char **)
if (U_FAILURE(status))
return 0;
ucol_close(collator);
+
+ UCalendar *cal = ucal_open(0, -1, "C", UCAL_GREGORIAN, &status);
+ UCalendar *x = ucp(cal);
+ ucal_close(x);
+
return 0;
}
Fix bundled pcre
Perhaps alternatively one can install a libpcre via OpenCSW.
--- a/qtbase/src/3rdparty/pcre/pcre_compile.c
+++ b/qtbase/src/3rdparty/pcre/pcre_compile.c
## -66,6 +66,8 ## COMPILE_PCREx macro will already be appropriately set. */
#endif
+#include <stdint.h>
+
/* Macro for setting individual bits in class bitmaps. */
#define SETBIT(a,b) a[(b)/8] |= (1 << ((b)&7))
Fix sha3
At least on Solaris 10/Sparc the functions fromBytesToWord and fromWordtoBytes are used by the code, thus:
--- a/qtbase/src/3rdparty/sha3/KeccakF-1600-opt64.c
+++ b/qtbase/src/3rdparty/sha3/KeccakF-1600-opt64.c
## -324,7 +324,7 ## static void KeccakPermutation(unsigned char *state)
KeccakPermutationOnWords((UINT64*)state);
}
-#if 0 // Unused in the Qt configuration
+#if 1 // Unused in the Qt configuration
static void fromBytesToWord(UINT64 *word, const UINT8 *bytes)
{
unsigned int i;
## -445,7 +445,7 ## static void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsign
#endif
}
-#if 0 // Unused in the Qt configuration
+#if 1 // Unused in the Qt configuration
static void fromWordToBytes(UINT8 *bytes, const UINT64 word)
{
unsigned int i;
Include/type/usage fixes
The uname() function is activated via a CPP construct on Solaris
and is declared in that header:
--- a/qtbase/src/corelib/io/qfileselector.cpp
+++ b/qtbase/src/corelib/io/qfileselector.cpp
## -51,6 +51,8 ##
#include <QtCore/QLocale>
#include <QtCore/QDebug>
+#include <sys/utsname.h>
+
QT_BEGIN_NAMESPACE
//Environment variable to allow tooling full control of file selectors
Under Solaris parent is unused in that code-path and the code gets compiled with -Werror ...
--- a/qtbase/src/corelib/io/qfilesystemwatcher.cpp
+++ b/qtbase/src/corelib/io/qfilesystemwatcher.cpp
## -77,6 +77,7 ## QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject
#elif defined(Q_OS_FREEBSD) || defined(Q_OS_MAC)
return QKqueueFileSystemWatcherEngine::create(parent);
#else
+ (void)parent;
return 0;
#endif
}
Under Solaris uid_t has an 'unexpected' sign (-> Werror). Casting it to ssize_t should be a portable and safe choice:
--- a/qtbase/src/corelib/io/qstandardpaths_unix.cpp
+++ b/qtbase/src/corelib/io/qstandardpaths_unix.cpp
## -132,7 +132,7 ## QString QStandardPaths::writableLocation(StandardLocation type)
}
// "The directory MUST be owned by the user"
QFileInfo fileInfo(xdgRuntimeDir);
- if (fileInfo.ownerId() != myUid) {
+ if (fileInfo.ownerId() != ssize_t(myUid)) {
qWarning("QStandardPaths: wrong ownership on runtime directory %s, %d instead of %d", qPrintable(xdgRuntimeDir),
fileInfo.ownerId(), myUid);
return QString();
Similar issue with threading code (Werror because of sign-mismatch in pointer cast). Casting to size_t should be a portable safe choice:
--- a/qtbase/src/corelib/thread/qthread_unix.cpp
+++ b/qtbase/src/corelib/thread/qthread_unix.cpp
## -231,7 +231,7 ## QThreadData *QThreadData::current()
}
data->deref();
data->isAdopted = true;
- data->threadId = (Qt::HANDLE)pthread_self();
+ data->threadId = (Qt::HANDLE)((size_t)pthread_self());
if (!QCoreApplicationPrivate::theMainThread)
QCoreApplicationPrivate::theMainThread = data->thread;
}
## -314,7 +314,7 ## void *QThreadPrivate::start(void *arg)
thr->d_func()->setPriority(QThread::Priority(thr->d_func()->priority & ~ThreadPriorityResetFlag));
}
- data->threadId = (Qt::HANDLE)pthread_self();
+ data->threadId = (Qt::HANDLE)((size_t)pthread_self());
set_thread_data(data);
data->ref();
## -393,7 +393,7 ## void QThreadPrivate::finish(void *arg)
Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW
{
// requires a C cast here otherwise we run into trouble on AIX
- return (Qt::HANDLE)pthread_self();
+ return (Qt::HANDLE)((size_t)pthread_self());
}
#if defined(QT_LINUXBASE) && !defined(_SC_NPROCESSORS_ONLN)
The struct in_addr has a struct as first attribute on Solaris, thus gives a warning with GCC when initializing with {0} - thus, yields an error during Qt-compile:
--- a/qtbase/src/network/socket/qnativesocketengine_unix.cpp
+++ b/qtbase/src/network/socket/qnativesocketengine_unix.cpp
## -63,6 +63,7 ##
#endif
#include <netinet/tcp.h>
+#include <string.h>
QT_BEGIN_NAMESPACE
## -737,7 +738,8 ## QNetworkInterface QNativeSocketEnginePrivate::nativeMulticastInterface() const
return QNetworkInterface::interfaceFromIndex(v);
}
- struct in_addr v = { 0 };
+ struct in_addr v;
+ memset(&v, 0, sizeof(struct in_addr));
QT_SOCKOPTLEN_T sizeofv = sizeof(v);
if (::getsockopt(socketDescriptor, IPPROTO_IP, IP_MULTICAST_IF, &v, &sizeofv) == -1)
return QNetworkInterface();
The header comment of X11/Xutil.h lists X11/Xutil.h as dependency, and indeed, without that include some declarations are missing under Solaris.
--- a/qtbase/src/plugins/platforms/xcb/qxcbmime.cpp
+++ b/qtbase/src/plugins/platforms/xcb/qxcbmime.cpp
## -46,6 +46,7 ##
#include <QtCore/QBuffer>
#include <qdebug.h>
+#include <X11/Xlib.h>
#include <X11/Xutil.h>
#undef XCB_ATOM_STRING
The X11/extensions/XIproto.h is not C++-safe under Solaris. That means it contains struct members names class. Fortunately, the header does not seem to be used in that code.
--- a/qtbase/src/plugins/platforms/xcb/qxcbxsettings.cpp
+++ b/qtbase/src/plugins/platforms/xcb/qxcbxsettings.cpp
## -43,7 +43,7 ##
#include <QtCore/QByteArray>
-#include <X11/extensions/XIproto.h>
+//#include <X11/extensions/XIproto.h>
QT_BEGIN_NAMESPACE
/* Implementation of http://standards.freedesktop.org/xsettings-spec/xsettings-0.5.html */
The pow() function has some overloads as specified in the C++ standard which introduce ambiguities under Solaris. Fixing the types like this should be portable and safe:
--- a/qtdeclarative/src/qml/jsruntime/qv4globalobject.cpp
+++ b/qtdeclarative/src/qml/jsruntime/qv4globalobject.cpp
## -534,7 +534,7 ## ReturnedValue GlobalFunctions::method_parseInt(CallContext *ctx)
}
if (overflow) {
- double result = (double) v_overflow * pow(R, overflow_digit_count);
+ double result = (double) v_overflow * pow(double(R), int(overflow_digit_count));
result += v;
return Encode(sign * result);
} else {
Under Solaris, alloca needs another header:
--- a/qtdeclarative/src/qml/jsruntime/qv4stringobject.cpp
+++ b/qtdeclarative/src/qml/jsruntime/qv4stringobject.cpp
## -73,6 +73,11 ##
# include <windows.h>
#endif
+
+#if OS(SOLARIS)
+#include <alloca.h>
+#endif
+
using namespace QV4;
DEFINE_MANAGED_VTABLE(StringObject);
Fix deep mkdir
Qt does a 'deep' mkdir() (e.g. something like mkdir -p for e.g. creating a directory hierarchy, e.g. ~/.config/company/product. The Qt 5.2 algorithm may abort too soon on Solaris if an existing directory is located inside a non-writable NFS mounted parent - because in that case Solaris returns EACCESS instead of EEXIST.
--- a/qtbase/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/qtbase/src/corelib/io/qfilesystemengine_unix.cpp
## -579,6 +579,11 ## bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea
// on the QNet mountpoint returns successfully and reports S_IFDIR.
|| errno == ENOENT
#endif
+#if defined(Q_OS_SOLARIS)
+ // On Solaris 10, mkdir returns EACCESS on a directory which exists
+ // inside an NFS mount ...
+ || errno == EACCES
+#endif
) {
QT_STATBUF st;
if (QT_STAT(chunk.constData(), &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR)
Temporary files
Solaris also does not have mkdtemp():
--- a/qtbase/src/corelib/io/qtemporarydir.cpp
+++ b/qtbase/src/corelib/io/qtemporarydir.cpp
## -52,7 +52,7 ##
#endif
#include <stdlib.h> // mkdtemp
-#if defined(Q_OS_QNX) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
+#if defined(Q_OS_QNX) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID) || defined(Q_OS_SOLARIS)
#include <private/qfilesystemengine_p.h>
#endif
## -96,7 +96,7 ## static QString defaultTemplateName()
static char *q_mkdtemp(char *templateName)
{
-#if defined(Q_OS_QNX ) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
+#if defined(Q_OS_QNX ) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID) || defined(Q_OS_SOLARIS)
static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const size_t length = strlen(templateName);
Pthreads
Solaris does not have pthread_get_stacksize_np (the _np suffix stands for non-portable).
Solaris has another function for getting stack-address/size values. My attempt:
--- a/qtdeclarative/src/qml/jsruntime/qv4engine.cpp
+++ b/qtdeclarative/src/qml/jsruntime/qv4engine.cpp
## -73,6 +73,11 ##
#include "qv4isel_moth_p.h"
#if USE(PTHREADS)
+
+#if OS(SOLARIS)
+#include <thread.h>
+#endif
+
# include <pthread.h>
#endif
## -103,6 +108,11 ## quintptr getStackLimit()
} else
size = pthread_get_stacksize_np(thread_self);
stackLimit -= size;
+# elif OS(SOLARIS)
+ stack_t ss;
+ int r = thr_stksegment(&ss);
+ (void)r;
+ stackLimit = reinterpret_cast<quintptr>(ss.ss_sp);
# else
void* stackBottom = 0;
pthread_attr_t attr;
--- a/qtdeclarative/src/qml/jsruntime/qv4mm.cpp
+++ b/qtdeclarative/src/qml/jsruntime/qv4mm.cpp
## -67,6 +67,11 ##
#include <sys/storage.h> // __tls()
#endif
+#if OS(SOLARIS)
+#include <thread.h>
+#include <pthread.h>
+#endif
+
QT_BEGIN_NAMESPACE
using namespace QV4;
## -218,6 +223,11 ## MemoryManager::MemoryManager()
# if OS(DARWIN)
void *st = pthread_get_stackaddr_np(pthread_self());
m_d->stackTop = static_cast<quintptr *>(st);
+# elif OS(SOLARIS)
+ stack_t ss;
+ int r = thr_stksegment(&ss);
+ (void)r;
+ m_d->stackTop = static_cast<quintptr *>(ss.ss_sp) + ss.ss_size/sizeof(quintptr);
# else
void* stackBottom = 0;
pthread_attr_t attr;
I recommend a careful review of that code because my Qt-code does not use that Qt-module, thus, I did not test it much.
XKB extension
Qt 5 seems to heavily rely on the XKB extension. It seems that you can't build Qt 5 without XKB support. It comes bundled with xkbcommon.
First, make sure that it finds the right XKB database. Otherwise keyboard input does not work at all in your Qt programs!
Solaris does not have the default value /usr/share/X11/xkb. It has instead:
/usr/X11/lib/X11/xkb
/usr/openwin/lib/X11/xkb
But I havn't had luck with those - xkbcommon simply could not find any components with those.
I ended up with copying /usr/share/X11/xkb from a cygwin distribution to a custom path and configuring that as XKB database.
Whatever XKB you choose you have to configure it:
--- a/qtbase/src/3rdparty/xkbcommon.pri
+++ b/qtbase/src/3rdparty/xkbcommon.pri
## -1,7 +1,12 ##
QMAKE_CFLAGS += -std=gnu99 -w
INCLUDEPATH += $$PWD/xkbcommon $$PWD/xkbcommon/src $$PWD/xkbcommon/src/xkbcomp
+solaris-g++-64 {
+DEFINES += DFLT_XKB_CONFIG_ROOT='\\"/MY/XKB/CHOICE\\"'
+} else {
DEFINES += DFLT_XKB_CONFIG_ROOT='\\"/usr/share/X11/xkb\\"'
+}
### RMLVO names can be overwritten with environmental variables (See libxkbcommon documentation)
DEFINES += DEFAULT_XKB_RULES='\\"evdev\\"'
For testing it also make sense to check for NULL values in error message parameters:
--- a/qtbase/src/3rdparty/xkbcommon/src/xkbcomp/xkbcomp.c
+++ b/qtbase/src/3rdparty/xkbcommon/src/xkbcomp/xkbcomp.c
## -68,8 +68,11 ## text_v1_keymap_new_from_names(struct xkb_keymap *keymap,
log_err(keymap->ctx,
"Couldn't look up rules '%s', model '%s', layout '%s', "
"variant '%s', options '%s'\n",
- rmlvo->rules, rmlvo->model, rmlvo->layout, rmlvo->variant,
- rmlvo->options);
+ rmlvo->rules, rmlvo->model,
+ rmlvo->layout ? rmlvo->layout : "(NULL)",
+ rmlvo->variant ? rmlvo->variant : "(NULL)",
+ rmlvo->options ? rmlvo->options : "(NULL)"
+ );
return false;
}
There is also the possibility that your XServer does not even support the XKB extension. Again, I don't know if Qt 5 can be configured with disabled-XKB-support under X.
You can check your X-server like this:
xprop -root | grep xkb
Or call a random xkb-program, e.g.:
xkbvleds
Such call should not result in an error like:
Fatal Error: Server doesn't support a compatible XKB
In case your XServer does not have XKB - Qt programs are likely to segfault. Qt does not seem to really check for XKB support. It does not seem to have a fallback mechanism when XKB is not usable.
Examples
Some examples fail because of module quick not being found:
--- a/qtconnectivity/examples/bluetooth/scanner/scanner.pro
+++ b/qtconnectivity/examples/bluetooth/scanner/scanner.pro
## -1,4 +1,4 ##
-QT = core bluetooth quick
+QT = core bluetooth # quick
SOURCES += qmlscanner.cpp
TARGET = qml_scanner
diff --git a/qtconnectivity/examples/nfc/poster/poster.pro b/qtconnectivity/examples/nfc/poster/poster.pro
index d108b2a..d0d0659 100644
--- a/qtconnectivity/examples/nfc/poster/poster.pro
+++ b/qtconnectivity/examples/nfc/poster/poster.pro
## -1,4 +1,4 ##
-QT += qml quick network nfc widgets
+QT += qml network nfc widgets # quick
SOURCES += \
qmlposter.cpp
They are also built without.
make install
A gmake install surprisingly triggers the compilation of several modules not yet compiled. Thus it make sense to execute it in parallel:
$ gmake -j16 install
(assuming that your system has a sufficient number of cores)
QtHelp
The bundled QtHelp module is not build/installed with the main compile/install steps.
To fix that:
cd qttools
PATH=$MY_PREFIX/bin:$PATH qmake
gmake
gmake install
Open issues
when using a remote Cygwin-X connection some colors are weird - e.g. the standard widget-gray is some light-light-blue - any ideas where to start to look for that?
QtSVG is successfully built but displaying a small SVG (e.g. inside a QLabel) hangs the dialog - a truss -u : shows function calls inside libm/QtWidget - perhaps the system is just way too slow and/or some code-path is not optimized on Solaris/in combination with a X-forwarding over ssh
a Qt-Program prints on startup: Qt Warning: Could not find a location of the system's Compose files. Consider setting the QTCOMPOSE environment variable. - no idea what feature this is about
Conclusion
With those adjustments 'normal' Qt programs (without QtSvg) compile
and run fine under Solaris 10.

mmap brokes after strdup

I tried the following configuration with mmap:
open file (file is over 2 kB)
request statistics from file *f_file*
map file (file is smaller than a page, offset page 0, size is expected size)
verify values of *f_footer* in the map *f_fpage*
usage strdup
Code:
union{
...
struct {
char *f_fname;
struct clog_footer *f_footer;
char *f_fpage;
size_t f_size;
} f_ring; /* circular log file */
char *f_fname; /* Name use for Files|Pipes|TTYs. */
} f_un;
...
struct clog_footer {
uint32_t cf_magic;
};
...
1995 f->f_file = open(p+1, O_RDWR, 0 );
1996 if (f->f_file == -1) {
2000 }
2001 if (fstat(f->f_file,&sb)<0) {
2006 }
2014 f->f_un.f_ring.f_fpage = mmap(NULL,sb.st_size,PROT_READ|PROT_WRITE,MAP_SHARED,f->f_file,0);
2015 if (f->f_un.f_ring.f_fpage == MAP_FAILED) {
2020 }
2021 f->f_un.f_ring.f_footer = (struct clog_footer*)(f->f_un.f_ring.f_fpage + sb.st_size-sizeof(struct clog_footer));
2022 if (memcmp(&(f->f_un.f_ring.f_footer->cf_magic),MAGIC_CONST,4)!=0) {
2029 }
2031 f->f_un.f_fname = strdup (p+1);
...
I used read/write, file is filled with zero's up to 2 Kb. I parametrized mmap with file size and zero page size, but mmap fails to map the file.
Should the file to map have additional properties?
Is "0" a acceptable parameter as offset in mmap, once i want to map the file from beginning?