Apr 13

GNOME 3 Hate

Can anybody tell me why people are hating on GNOME 3 so much?  I can’t seem to quite figure it out.

The best that I can come up with is “Because it’s different.”  My Jack O’Neill response: “And? But? So? Therefore?”

I’ve been using GNOME 3 on Debian 7 for the past few months now, and I don’t see where all the hate is coming from.  I did a few things to tweak GNOME, but nothing drastic.  Sure, it may be a little annoying to not have a taskbar, but there are a bunch of extensions that give you a taskbar back if you want it.  Whenever you get a new program, often times you have to customize it to the way that you want it.  Everybody that’s complaining seems to be either a) hating change and/or b) unwilling to spend the time to customize things to how they want them.

When you get a new car, does it automatically match up with what your old car was like?  No, of course not.  When things are redesigned, there are going to be changes.  Some of them are bad.  Some of them are good.  Sometimes, it would help to read the manual.  Because then you might understand what is there and how to use it.  Because just opening something up, going “this is complicated and stupid, I’m going back to what I was using before” is not very productive to anyone.  Often I find that when things are changed, they do seem complicated and stupid.  But once I give it a chance, I can then better evaluate what is wrong/what is working, and how I can tweak the experience to better fit my working methods.

Thoughts on the FSF

Aside

I think this really points out my thoughts on the FSF the best.  Not that the FSF is bad in any way, or it doesn’t do useful stuff, but they seem to be living in the past.  I guess perhaps the point here is that if you don’t know what’s out there, and how things are used, it’s impossible to make things better.  It’s like creating software for a problem that you don’t understand, or writing a book.  You must first understand what the rules are, how people use them, and then you can create a better solution.

Nov 07

Thoughts on systemd

So the other day, I had to figure out if udev is still supported without using systemd, since the source trees have been merged, and we’re using Ubuntu at work which doesn’t use systemd. (answer: yes)  This research brought me to this systemd comparison page, detailing the differences between sytemd, Upstart, and SysV.  Not knowing much about init systems(besides Upstart and a little bit of SysV), systemd seems to have a lot of features in it – but as I’m reading these features, I’m wondering: should an init system do all of these things?

There seem to be a lot of things which aren’t particularly useful.  But perhaps they are(as I said, I’m not an expert on init systems).  They seem to be creating a particularly complicated system, and it seems to me that many of the features that they espouse could just as easily be handled by a separate program.  Of course, having a separate program does have its downsides, since it can make the startup logic more obtuse.

Also, I really like how in the ‘Miscellaneous’ table there’s a row for the SCM that is used.  I’m thinking “Who the hell cares?”.

Nov 01

Monitor System DBus

I’m currently writing a program which needs to listen to signals on the system DBus, and I needed a way to monitor the system bus.  I followed the directions here, but I came across a slight problem with that.  It turns out that the solution posted only allows you to listen for things that root sends out.  When I ran my program as an unprivileged user, I didn’t see any output in dbus-monitor, however I would see output if I ran the same program as root.  From what I can tell, the configuration posted will only allow you to see what root is sending on the bus, given that user=”root”.

Fortunately, there’s a simple fix for this:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE busconfig PUBLIC
  "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">

<busconfig>
  <policy context="default">
    <!-- Allow everything to be sent -->
    <allow send_destination="*" eavesdrop="true"/>
    <!-- Allow everything to be received -->
    <allow eavesdrop="true"/>
  </policy>
</busconfig>

Simply change the policy user to a policy context, and you can now see everything that’s on the bus.

As always, make sure that you remove this config once you’re done testing, otherwise it will be easy to circumvent security mechanisms that are in place.

Sep 03

Good Documentation

I just came across this post on Slashdot on how to create good documentation.  This is a good guide.  Too often, documentation that exists out there is not particularly great, or good at showing you how to do something.  This is the reason that I created my D-Bus tutorial – and I hope that it’s been useful to people.  Similar to how Log4J2 didn’t have excellent documentation – it makes sense once you know how things work, but there isn’t a nice, low-knowledge way to go about this.  In fact, right in the documentation it says:

An understanding of how loggers work in Log4j is critical before trying to configure them. Please reference the Log4j architecture if more information is required. Trying to configure Log4j without understanding those concepts will lead to frustration.

…and that’s about the point at which my eyes glaze over.

I’m not saying that the Log4J2 documentation is horrible, but it could be better and somewhat more structured as Steve Losh said.

Aug 22

Log4J2 Setup

I feel that a decent guide on how exactly Log4J2 is setup is in order, because there isn’t a real clear explanation on Apache’s site. Now Apache, I know you guys make a lot of stuff, but seriously a lot of this stuff is just over-engineered.

Alright, on to the configuration stuff!

Here’s an example config file, with an explanation as to what is going on here(at least as far as I can understand it)

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
  <appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
    <File name="File" fileName="${sys:logFilename}">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </File>
  </appenders>
  <loggers>
    <root level="ERROR">
      <appender-ref ref="Console" />
      <appender-ref ref="File"/>
    </root>
    <logger name="com.rm5248.Logtest2" level="ALL" />
  </loggers>
</configuration>

Okay, let’s start at the very top with the configuration tag:

<configuration status="OFF">

If you change the ‘status’ part of this to a level such as “ALL”, you’ll notice that Log4J2 sends out A LOT of information. As far as I can tell, this is just logging information that is part of Log4J2.

Alright, let’s go on to the appenders. When you create a logger, there are several appenders that you can use to send information to various places. The two appenders that we have here are for the console(i.e. System.out) and a file.

<appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
    <File name="File" fileName="${sys:logFilename}">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </File>
  </appenders>

The PatternLayout that they have determines how the information will be printed out. For the File appender, there is a fileName property with sys:logFilename. This means that the logger will look for the system property of logFilename. This can be set by either:

  1. passing -DlogFilename=XXX to the program
  2. System.setProperty( “logFilename”, XXX )

If you use option #2, you must also reconfigure the logger as shown in this StackOverflow post.  Fortunately, the patters are in fact well documented.  There are a lot of other appenders out there to append to different things, but we’re not worried about that at the moment.

Okay, now on to the final section: the loggers themselves.

  <loggers>
    <root level="ERROR">
      <appender-ref ref="Console" />
      <appender-ref ref="File"/>
    </root>
    <logger name="com.rm5248.Logtest2" level="ALL" />
  </loggers>

As you can see here, we have a root logger and a specific logger.  The root logger has a level of ERROR, which means that everything descending from the root logger will print out all ERROR messages.  The root logger will also go two places: the Console logger and the File logger.

The second logger besides the root logger is logging just one specific file.  The log level for that file is ALL, which overrides the ERROR log level of the root logger.  Thus, all log messages from that file will be logged.  These messages will also be sent to both the CONSOLE log and FILE log, as those settings are inherited from the root logger.  Let’s say that we want to send those log messages to the FILE, but everything will also go to the CONSOLE. We would do something like this:

    <root level="ERROR">
      <appender-ref ref="Console" />
    </root>
    <logger name="com.rm5248.Logtest2" level="ALL" >
       <appender-ref ref="File" />
    </logger>

Since the more specific logger inherits from the root logger, all log messages from com.rm5248.Logtest2 go to the FILE and the CONSOLE.  There’s more stuff that you can do here with that, but I haven’t really delved into it too deeply.

Anyway, here’s the code that I was using when I was playing around with this.  Hopefully this will help you to get started.

XML Config File:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
  <appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
    <File name="File" fileName="${sys:logFilename}">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </File>
  </appenders>
  <loggers>
    <root level="ERROR">
      <appender-ref ref="Console" />
      <appender-ref ref="File" />
    </root>
    <logger name="com.rm5248.Logtest2" level="ALL" />
  </loggers>
</configuration>

LogTest.java:

package com.rm5248;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.XMLConfigurationFactory;


public class LogTest {

	private static Logger logger = LogManager.getLogger( LogTest.class );

	public static void main( String[] args ){
		File logConfigFile = new File( XML_CONFIG_FILE_GOES_HERE );
		System.setProperty( "logFilename", "filename.log" );		

		try {
			FileInputStream fis = new FileInputStream( logConfigFile );

			XMLConfigurationFactory fc = new XMLConfigurationFactory( );
			fc.getConfiguration(  new ConfigurationFactory.ConfigurationSource( fis ) );

			URI configuration = logConfigFile.toURI();
			Configurator.initialize("config", null, configuration);

			org.apache.logging.log4j.core.LoggerContext ctx =
					(org.apache.logging.log4j.core.LoggerContext) LogManager.getContext( true );
			ctx.reconfigure();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		logger.debug( "hi debug" );
		logger.info( "hi info" );
		logger.error( "hi error" );

		Logtest2.doSomething();
	}

}

Logtest2.java:

package com.rm5248;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Logtest2 {
	private static Logger logger = LogManager.getLogger( Logtest2.class );
	
	public static void doSomething(){
		logger.debug( "hello" );
		logger.error( "error?!" );
		logger.warn( "warning" );
		logger.info( "la la la" );
	}
}
May 07

Java Scanner and Input Streams

This just took me a stupid long time to figure out, so I’m leaving it here for future reference.

In Java, the easiest way to read lines is using Scanner.  For work, I had written a quick Linux-only serial port implementation, with which I then took ideas from that for use in my cross-platform JavaSerial library.  What I was doing before was simply using a scanner to look for text coming in on the serial port, and splitting it up based on the lines using the scanner.  This worked fine.

Then I used JavaSerial.  And the Scanner wouldn’t work.

AT ALL.

As it turns out, Scanner doesn’t like using the normal read() method found in InputStream.  It instead uses the read() method which takes in a byte[] array.

If this was documented anyplace in the Javadocs, that would be good.  But it’s not.

UPDATE: 

I’ve figured out what the problem was. According to the Javadocs for the read( byte[], off, len ) method, it will block until it reads the entire length requested, which is stupid.  My implementation reads until either the end is reached OR there is no more data available(using the available() method).  See my implementation here.

Apr 28

C Enums

Enums in C are something special.  They’re not strongly typed at all.  As it’s pointed out, sometimes enums are used for making bit values, which is rather convenient.  However, it would be very good if enums could be strongly typed.  So, here’s my thought on how to make enums in C better.

Enums should be strongly typed.  The following should throw a compile error about assigning an integer to an enum:

enum MyEnum{ Value1 = 0, Value2 = 1 };
enum MyEnum variable = 0;

However, since this is C, casting should be allowed. So you could do this:

enum MyEnum{ Value1 = 0, Value2 = 1 };
enum MyEnum variable = (enum MyEnum)0;

Now about the bitset. I think that the best way to do this is to create a new enum-like type, called bitfield. It would have a syntax nearly itentical to enum, and the compiler could auto-increment the bitfields as well, so that you can ensure bitfields are always good:

bitfield MyBitfield{ Value1 = 0, Value2 = 1, Value3 = 3, Value4 = Value2 | Value3 };

The compiler would then go through and ensure that all bitfields are valid. You could also put more than one bitfield value into a bitfield, and the compiler would ensure that they’re both of the same type. So, this would be valid:

bitfield MyBitfield{ Value1 = 0, Value2 = 1, Value3 = 3, Value4 = Value2 | Value3 };
bitfield variable = Value1;  /* Works */

/* When passing in a method */
void foo( bitfield parameter ){
  if( parameter & Value2 ){
    /* Do something */
  }
}

This would create a much more type-safe form of enums for C. While not backwards-compatible, it’s not a dramatic shift in how enums are used, so it wouldn’t require huge changes.

Apr 18

Software Licences

So I came across this article via Slashdot today, and I figured that I’d post some thoughts on my programming utils and their license.

The part that I really noticed was:

…younger developers may be choosing more permissive licenses as a way of pushing back against what they see as a “permission culture.” They prefer to let other developers just do whatever they want with their code – and, rightly or wrongly, this might be a reason why many projects are released with no license whatsoever.

This is basically what I was going for.  I don’t care what people use my software for.  It is there for people to use.  In that regard, the WTFPL may be a better choice, but I’m comfortable enough with the MIT license.  As long as proper credit is given, that is good enough for me.  The code is released in the hope that it will make other people’s lives easier.

Apr 03

Auto-generation of environments

So I’ve been re-playing GTAIII lately, and I thought of something.  How would one make a full city, with full interiors for every building that is there?  Couldn’t we just generate all this stuff at run-time?

This makes a lot of sense.  The code size becomes larger, but the code size is generally pretty insignificant compared to the size of the assets of the game.  If we define basic things such as how things go together, we could get something cool here.  For example, an office environment could have desks and chairs, and chairs should normally be next to desks.  Cubicle walls follow the same general footprint.  You don’t even need to randomly generate these things per-se; in order for everybody to have the same room, just have a function call which takes an int as an argument all the time; like a pseudo-random number generator, you’d get the same output every time that you ran it.  Ideally, what you would have is each floor of a building being a certain input to this generator of floors.  You don’t need to run through the code to generate the floor unless the player actually goes up to the floor. The environment artist also doesn’t have to create the floor at all, all he would have to do is to say “Okay, these are the floor dimensions. Here is the number.  Generate!” and it would do it.

It could work.  I’m not going to try and implement this, because it’s probably hard and I don’t really have anything to use it for anyway.  But it could be cool.