Friday, March 16, 2018

VNC Troubleshoot Cannot access vdagent virtio channel /dev/virtio-ports/

On Centos 7, the vncserver started for each service is able to launch and users can login remotely. Within 1 minute, this service crashes and the usual command (see below) to start the vncserver fails.

$ sudo systemctl start vncserver@:1

The reason for this failure is capture in the command;

$ sudo systemctl status vncserver@:1

There were 2 items to take note,
  1. Users were launching the vncviewer almost immediately upon the server boot up.
  2. The following error appears "Cannot access vdagent virtio channel /dev/virtio-ports/" upon checking the status.

Whats on the Linux?

Centos Linux version 7.4.1708 (Core)
Tigervnc version 1.8.0

Spice [reference Fedora]

Spice aims to provide a complete open source solution for interaction with virtualized desktop.  The Simple Protocol for Independent Computing Environments (SPICE) is used for client-server communication. Spice adds a QXL display device to QEMU and provides drivers for this device for both X and Windows. It also provides a Spice server and VDAgent to handle connections and transmit the information via the SPICE protocol to clients. The Spice project provides a Linux, Windows, and HTML5 client. There are experimental Mac OS X and Android clients as well.

This /dev/virtio-ports is created in this feature that modifies the current single-port virtio-console device to guests running on top of qemu and kvm. It exposes multiple ports to the guest in the form of simple char devices for simple IO between the guest and host userspaces. It also allows for multiple such devices to be exposed, lifting the current single device restriction.

Somehow, these were installed on the server.

$ rpm -qa \*spice\*

The RPM documentation on spice-vdagent states
"* Client mouse mode (no need to grab mouse by client, no mouse lag)
this is handled by the daemon by feeding mouse events into the kernel via uinput. This will only work if the active X-session is running a spice-vdagent process so that its resolution can be determined.
* Automatic adjustment of the X-session resolution to the client resolution
* Support of copy and paste (text and images) between the active X-session and the client"

I make an assumption that if no virtualisations are needed on the server, its a matter of deleting these packages. However, I have an Android Emulator that have dependency on the virtio-ports. Its still a question mark if VNC depends on spice-vdagent.


Step 1. Start SPICE agent.

At the command line on the host server, start the spice agent.
$ sudo systemctl start spice-vdagentd.service

Check and ensure that this service runs at boot up.
$ sudo systemctl show spice-vdagentd |grep enable

Step 2. Give host server time

Allow the Linux server to fully boot up all processed before attempting to start a VNC client session.


Monday, March 12, 2018

Laravel 5 and Error key was too long

The server was running PHP applications without any fuss, everyone is happy on this 12th March 2018. Laravel 5 came in that one day and a simple application was launched to show the default Laravel welcome screen. The next step was to create a CRUD application with storage to the local database.

A Model is created of a simple Task object. The room fell silence after the command, php artisan migrate

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_uniq(email))

What was wrong? Never mind that, lets see whats on the server!

  • Centos version 7.4.1708
  • Apache httpd  version Apache/2.4.6 (CentOS)
  • Mariadb (MySQL fork) version 5.5.56-MariaDB
  • PHP version 7.2.2 (cli) with Zend Engine v3.2.0
  • Laravel 5.6.7
  • Composer versioon 1.6.3
  • npm version 3.10.10

All of above are tested and working on its own. Going back to analyse the error, its database related. The respective tables of migrate, users were generated in the database, but the new model "task" isn't.The related code is in the file <laravel5>/database/migrations/2014_10_12_000000_create_users_table.php

On the database side, changed Collation to utf8mb4_unicode_ci but the error is still there. This is a 4-byte UTF-8 Unicode Encoding and as described in MySQL 5.5, it is
  1. In UTF8 it uses 3 bytes per character, containing only BMP characters. Utf8mb4 supports maximum 4 bytes per character and includes supplementary characters. 
  2. Utf8mb4 is a superset of Utf8.
  3. To save space, utf8mb4 is to use VARCHAR instead of CHAR type for BMP characters. 
 Changing a table from utf8 to utf8mb4 can be done with
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

ALTER TABLE `users` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;


Make the whole Laravel application and the database server utf8mb4 aware.

Step 1. Edit file  <laravel5>/config/database.php

'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
DYNAMIC allows to store of long key indexes.

Step 2.  Edit file /etc/my.cnf

# default character set and collation
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4

# utf8mb4 long key index
innodb_large_prefix = 1
innodb_file_format = barracuda
innodb_file_format_max = barracuda
innodb_file_per_table = 1

 Step 3. Edit file /etc/my.cnf.d/client.cnf


Step 4. Restart database server

Stop then start the database server with

$ sudo systemctl stop mysqld
$ sudo systemctl start mysqld


Points to note

The error states maximum key length is 767 bytes for the email field. In Laravel 5 the migration file for "Users" declared a string that gets created in the Mariadb database. Problem in question is adding the "unique" string that get generated in the database "Users" for field "email" with type VARCHAR(255) and collation utf8mb4. MySQL has to actually index the whole value to complete the operation. This calculates to give maximum size of

255 characters x 4 bytes = 1,020 bytes (MAXIMUM BYTES)

This looks like sufficient space, but why the error?
When Laravel writes/reads data to MySQL, it utilises a call to the local MySQL client/server that takes this as default of uf8 which is having maximum 3 bytes per character (due to the mysql default client/server settings). A little bit of calculation gives

255 characters x 3 bytes = 765 bytes (MAXIMUM BYTES)

In the above solution, there is access to modify the database configurations. What if you do not have such an access? The solution is to reduce the default string length sent by Laravel. Taking 191 as maximum characters, we get

191 characters x 4 bytes = 764 bytes

Edit file <laravel5>/app/Providers/AppServiceProvider.php

Add after the "use .... \ServiceProvider;"
use Illuminate\Support\Facades\Schema;

Add in the "public function boot( )"

Save and from the project's main folder, run migration
$ php artisan migrate

Alternatively, changed the field "email" that was declared unique to collation "utf8". It worked for me, but some people have mentioned it didn't work for them.


Monday, February 26, 2018

Installing Nodejs and NPM

Nodejs provides JavaScript with a way to optimise single threaded and single CPU core processing. 
NPM is a package manager to deliver applications. Its like yum on Centos linux.

In this case, I am installing Cordova for Android development on Centos 7.4 and it required nodejs along with npm. Hence, this article came along the way.

Step 1: Install Epel repository

$ sudo yum install epel-release  
$ sudo yum info nodejs
It shows nodejs version 6.12.3

Step 2: Install nodejs

Install the development environment then nodejs. This will install together the npm (version 3.10.10)
$ sudo yum --setopt=group_package_types=mandatory,default,optional groupinstall "Development Tools"
$ sudo yum install nodejs

Check installed version
$ node -v
$ npm -v

Step 3: Run Hello World

Create this script and name it as helloworld.js to test on a command line and the web browser.

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('<p>This is <b>Hello World</b></p>');
console.log('This example is my world!');

At a command line, type
$ node helloworld.js

This should display the output on the command line.
Next, open a web browser and type the following url


Continue with Cordova installation from previous article.

Remove Defunct or Zombie processes

On Linux systems (Centos, Fedora, Ubuntu, Mint, Puppy), a running application is identified by one or more processes. Example when running a document with LibreOffice Writer, the process thats related is oosplash and soffice.bin as can be seen below.

tboxmy  5262  0.3  0.0 299672  3272 ?        Sl   10:17   0:00 /usr/lib64/libreoffice/program/oosplash --writer
tboxmy  5277  3.1  1.1 1273804 89564 ?       Sl   10:17   0:01 /usr/lib64/libreoffice/program/soffice.bin --writer --splash-pipe=5

Shown in bold, the unique process identification (id) are 5262 and 5277 for the two processes. Upon using the command ps xl, it can be seen that process 5277 is spawned by process 5262. Making 5262 a parent to 5277.

What is a defunct process?

A "defunct" processes is referred as a dead process that still hogs memory resources. Its not much a problem having a defunct process, but when the system starts to have more defunct processes, the system can slow down and affect applications.

This defunct or dead process that still lingers on the system is also known as zombie process. Most appropriate, like in a horror flick! You can't kill a zombie that is already dead, so what can you do? Watch the next zombie show and try figuring that out. Luckily, on Linux systems, a zombie doesn't go around attacking or destroying resources. It only lingers on, hogging on to resources once given to it when it was a live process, at one time.

What brings about this zombie? On Linux its mostly due to bad programming that lead to errors and bugs that are not handled by the application itself.

Dealing with defunct process

Don't attempt to bring back to live a zombie process. Seek out the zombie and terminate from the system. Here are commands to handle an example zombie processes (defunct) with process id 5277.

Where are the zombie processes?
$ ps ef |grep defunct
5277 ?        Z      0:01 [example-app] <defunct>

Notice the word "defunct" and status as Z (for zombie) for the process 5277. That, is our zombie. Did you find any zombie's in your system?

The command kill is used to terminate any process and free system resources such a memory (RAM). The problem with zombie processes is that, they are dead, and can't be killed (not most of the time). What is done however, is to identify the parent process (the one responsible for creating the zombie) and terminate that process.

Identify the parent process id (5262) and terminate it.
$ ps -o ppid 5277

$ kill -9 5262
$ ps ef |grep defunct

That is the end of the zombie. In some cases, a zombie might be holding on to a resource and it will take sometime for it to detach (give it a bit of a wait).

There are other methods to look for zombies. E.g. the ps command provides a method of displaying the parent hierarchy as follows;
$ ps xlf |grep defunct

Or in the command top, look at the second line for number of zombie processes.

What if the zombie keeps appearing on a daily basis for the same process? 

This is a problem, but sometimes its not apparent as zombie's live among the running processes without bothering anyone. Let me know if you have other than the suggestions I have list below.
  • See if there is a newer version of the application or an alternative (such as different architecture, from a different source) and install. 
  • It is possible that the application itself is not the problem. Identify any other related applications or module that is causing this zombie. Then update or find an alternative application to use.
  • Report to the application project team for a solution.

Friday, February 23, 2018

Cannot open display Error when using VNC

After opening VNC Viewer on MS Windows 10 and connecting to the Centos 7, the desktop appears as planned. However, there is an error when running some apps such as system-config-printer. The error is

Gtk-WARNING **: cannot open display:1

Good to note that the VNC server was providing the session at display 1 on port 5901. If you are running the display on another port, it wouldn't matter.


At the user's terminal (AND as that user NOT sudo or root), add localhost to the xhost permission. Type

$ xhost +localhost

And this allows system-config-printer to run.

Wednesday, February 14, 2018

Cordova: Accepting user input

What would be the first thing in programming? A simple use of variable and user text input comes to mind. Following the previous post (link here), the Cordova programming environment is set up for Android. The existing files will be edited to do the following;

The HelloWorldApp when started, will prompt the user to enter a city name.

The user enters a city name and press "OK" button. The city name will be displayed on the app.

Step 1. Position the text to display user response.

Using a text editor, open the file index.html in HelloWorld/www and replace the previous <p> tag with the text "Hello World" with;

<div id="answer"></div>

Save the file.

Step 2. Prompt user at apps startup and display the reply.

Open the file index.js in HelloWorld/www/js

Add our function called getAnswer to the end of the file;
function getAnswer() {
    var ans = prompt("Name your city");
    if (ans.length > 0) {      
        document.getElementById('answer').innerHTML = "";      
        document.getElementById('answer').innerHTML = ans + " is a great place.";
    } else {      

Activate the getAnswer function in the initialize:function( )by adding after document.addEventListener(...);

getAnswer( );

Step 3. Build and launch the app.

At the command line interface (CLI) or the command terminal, type

$ cordova build android
$ cordova run android

This will launch the default emulator.

In order to test the app, at any time after editing to the source files, just follow this Step 3.


Android emulator error: 
The connection to the server was unsuccessful. (file:///android_assets/www/index.html)

Edit the file config.xml in HelloWorld folder. Add the following line after the </platform> tag.

<preference name="loadUrlTimeoutValue" value="700000" />

Build and launch the app.

Tuesday, February 13, 2018

How to Install Cordova for Android Development

One challenge in developing a mobile application is in choosing a mobile environment. Apache Cordova allows building of an application through the use of Java for Android, AngularJS, SCSS to create reusable code across platforms. I suggest that some study is done on those languages in order to fast track learning. Cordova supports several development platforms, for this article, its focus is on Android platform.

Cordova Installation

Here are the steps to get started on a command line with installation of Cordova and launching the Android emulator on MS Windows 10 (version 10.0.16299). All the versions mentioned here are those that I am using for this article.

1.Install Base Environment

Cordova relies on well known development tools to generate the latest mobile application. Install Java Development Kit (version 8 or newer), Android studio, Node.js and git. Ensure all these are working.
  1. Java Development Kit. This should be version 8 or newer and configure JAVA_HOME.
  2. Android Studio (This article is version 2.3.3). Install the required SDK platform (I choose Android 7.1.1 Nougat), SDK Tools comprising of Android SDK Tools (version 26.1.1), Android SDK Platform-tools (version 27.0.1) and Android Support Repository (version 47.0.0). In SDK Tools, install Android Emulator. On MS Windows platform, also install HAXM (I have version 6.2.1).
  3. Node.js. This article is version 6.9.1 with npm 3.10.8. 
  4. Optional: GIT (version
Ensure environment variables are configured for JAVA_HOME and ANDROID_HOME

Then at the command prompt type (do not type the dollar sign);
$ npm install -g cordova

On linux
$ sudo npm install -g cordova

2. Creating Hello World App.

We will create a Cordova project in a folder HelloWorld. This will be in io.cordova.project with the app title of HelloWorldApp.
$ cordova create HelloWorld io.cordova.project HelloWorldApp
$ cd HelloWorld

Here is the syntax to create any project
cordova create [project_name] [package_name] [apk_name]

Open the folder platforms, notice it is empty.
Cordova Project folder for HelloWorld

Open and identify the codes in index.html located at

In HelloWorld\www edit index.html to display Hello World. At end of the app tag, add 1 line
<div class="app">

<p>Hello World</p>

3. Install Android Platform.

When it is the first time creating a project, the target platform has to be added. Here its created in a folder CordovaProject.
$ cordova platform add android

Have a look at the Android source files are located at in


Default file

Each time the apps code is modified, the project is compiled and run in an emulator OR on a mobile device. Compile and build the project for the Android platform.
$ cordova build android

Start the apps in an emulator. The default emulator manager is by Genymotion and the default emulator is Pixel with Android API 25.
$ cordova emulate android.

If you intend to plug in your Android device to run the app, or  start the apps in an external device, type
$ cordova run android

4. Tips

List existing platform installed and what platform is available.
$ cordova platform ls

Blog Archive